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; }
</style>
</cfsavecontent>

 

Main Template file

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

</head>

Subscribe

  • RSS Feed for Posts


This entry was tagged .

Updated: 2012-05-03

Phil LaNasa

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <font color="" face="" size=""> <span style="">