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>

Tags:

Leave a Reply

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