Need a Vacation from Minification – Try to on-the-fly minify

Sorry for the ridiculous post title, but I just had to. What I'm talking about is the desire to keep your HTML output condensed, but not to make development difficult in the process.

For example, if you want a custom chunk of CSS on a given page, you might want to drop inline, in your <head>. But, if you're like me, you can't stand it when the page source shows dozens of lines of CSS/JS before you reach the <body>.

So, why not minify that CSS on-the-fly.

ColdFusion example

Page-specific CSS

<cfsavecontent variable="mycss">
<style type="text/css">
   h1 { font-size: 2em; }
   h2 { font-size: 1.5em; }


Main Template file

<!--- nicely minified CSS code below --->
<cfoutput>#Replace(Replace(mycss, chr(9), "", "ALL"), chr(13) & chr(10), "", "ALL")#</cfoutput></cfif>


Why follow me on Twitter?

  • I tweet about new technologies, services or libraries I find interesting
  • Yeah, sometimes I'll post a pet-peeve or rant about something trivial
  • If I discover something that made my web development life easier, I share it
  • I'll shout out any handy tip that I think might be useful to other devs

Tagged .

Updated: 2012-05-03

Phil LaNasa follow us in feedly