Home | Random | Downloads | About | Hikes | 7,184,851,754 | Search | Feed

Minify and inline CSS for ASP.NET MVC

ASP.NET has a CssMinify class (and a JavaScript variant as well) designed for use in the bundling pipeline. But what if you want to have your CSS minified and inline? Here is an action that is working for me (rendered into a style tag on my _Layout.cshtml using @Html.Action("InlineCss", "Home")).

public ActionResult InlineCss()
{
    BundleContext context = new BundleContext(
        new HttpContextWrapper(System.Web.HttpContext.Current), 
        BundleTable.Bundles, 
        "~/Content/css");
            
    Bundle cssBundle = BundleTable.Bundles.GetBundleFor("~/Content/css");
    BundleResponse response = cssBundle.GenerateBundleResponse(context);
           
    CssMinify cssMinify = new CssMinify();
    cssMinify.Process(context, response);

    return Content(response.Content);
}

Note that I'm using this to inline CSS for this blog. The pages are cached so I'm not worried about how well this action performs. My blog is also basically all landing pages so I'm also not worried about caching a non-inline version for later use, I just drop all the CSS on every page.

Book reviews for July 2014

Web Analytics 2.0: The Art of Online Accountability & Science of Customer Centricity [With CDROM] by Avinash Kaushik

Web Analytics 2.0: The Art of Online Accountability & Science of Customer Centricity [With CDROM] by Avinash Kaushik

5/5

Deep, evergreen advice on web analytics. This book is grounded in the trenches and is full of practical advice and reality. Works well to read all the way through and to dip into for specific topics.

 

The Divide: American Injustice in the Age of the Wealth Gap by Matt Taibbi

The Divide: American Injustice in the Age of the Wealth Gap by Matt Taibbi

5/5

Barnstorming tirade against injustice in the US law enforcement and legal systems. Nothing in here was news to me, but laid out story after story it's breathtaking. Minor welfare infractions leading to jail time, institutionalized fraud ignored. Banks get away with money laundering and theft while in some places standing on the street is a crime. Once you've worked up a full head of rage you realize that Obama is as bad as Bush is nearly as bad as Clinton. The failure is in politics and this book is a depressing catalog of the symptoms.

 

Tedious Feed Update

Tedious Feed Update

If you subscribe to I Thought He Came With You via RSS please switch to this new feed and delete the old one.

Longer version... this blog has used FeedBurner for ever but I managed to get locked out a couple of years ago. I upgraded to Google Apps for Domains and part of the process was transitioning various services over to a temporary account and then back to the new one. Most of them made it over but FeedBurner got orphaned somehow.

I've emailed, left forum posts etc but no luck. Google doesn't really do customer service so despite actually paying them I seem to be out of luck. Also, Google hates RSS so FeedBurner probably isn't the right long term tool even if I could get back into my account.

I've been meaning to do something about this for a while but as it was working it wasn't a top priority. This changed when my blog got hacked a couple of times in a row - I'm not sure if it was the software (I'd been using BlogEngine.net) or my hosting provider but it's painful to fix and I decided I needed a change. I Thought I Came From You is now running on a home grown platform. It should be more stable, faster (some quick benchmarking suggests twice as fast so far) and not get hacked quite so often.

So switch to http://ithoughthecamewithyou.com/syndication.axd for updates (I can't recommend Feedly highly enough) and delete the old feed. If you have any problems leave a comment below or send me an email.

Bay Bridge, Old And New

Bay Bridge, Old And New

Book reviews for June 2014

Advanced Web Metrics with Google Analytics by Brian Clifton

Advanced Web Metrics with Google Analytics by Brian Clifton

4/5

Very helpful book, but a generation out of date. Does not cover universal analytics or the new user ID collection but is a great foundation as long as you know this. I'll buy the next edition when/if it becomes available.

 

Summer Solstice 2014

Summer Solstice 2014

It's the start of Summer in the Northern Hemisphere, Winter if you live south of the equator or in San Francisco. Rendered in Catfood Earth.

Party Limits

Party Limits

What if as well as Term Limits we had Party Limits - the same political party cannot win more than three or four times in a row?

Representative Alan Lowenthal has introduced the Let the People Draw the Lines Act which would seek to prevent gerrymandering by taking redistricting out of the hands of the politicians for the states that haven't done this already (California, Arizona, Washington and Idaho have independent commissions).

This is a good idea, but I'd go further. Let's introduce Term Limits where we don't already have them and then add Party Limits. The same politician can only hold on to their seat for two to three terms and additionally the same party can't hold the seat for more than three to four terms. We break up any kind of political monopoly and reduce the incentive to rig the system to keep the same incumbent in power.

We'd probably get more political diversity as well as fewer career politicians. It's a better solution to daisyworld.

Book reviews for May 2014

The Quarry by Iain Banks

The Quarry by Iain Banks

4/5

This was a hard book to start because it's so sad to know that there will never be another Iain [M] Banks novel. I fell in love with his work after picking up The Wasp Factory with some birthday money in Guildford. I had (and loaned and lost) one signed book, Feersum Endjinn, which was the only really awful one. The Quarry was short, better than I thought it would be, not as good as his best. He'll be missed.

 

A Short Gentleman by Jon Canter

A Short Gentleman by Jon Canter

4/5

Unbearably British. Very funny.

 

From Alta Plaza Park

From Alta Plaza Park

Coyote

Coyote

Coyote on Lovers' Lane in The Presidio.

Next Page

I Thought He Came With You
Robert Ellison's blog.

Like I Thought He Came With You on Facebook