Thursday, November 12, 2009

new and improved super GZIP js/css with coldfusion

so a long time ago a blogged about using GZIP libraries in java to compress output on the fly. Since then i have made some tweaks to this technique.

1. I only have 2 SCRIPT tags in my pages.
<script src="/js/index.cfm?filenames=prototype.js,otherglobaljs.js....."
<script src="/js/index.cfm?filenames=jsonlyusedonthispage.js"

2. My index.cfm uses combine.cfc to compbine, minify and set the correct HTTP expiration headers on my code:

http://code.google.com/p/combine-cfc/

3. I gzip the resulting output back to the page if the browser supports it. See the full index.cfm below!

<cfsetting showdebugoutput="false" enablecfoutputonly="true">
<cfparam name="fileNames" default="">
<cfparam name="showRaw" default="false">


<cfset oCombine = createObject("component", "js.combine.combine").init(
enableCache: true,
cachePath: expandPath('output'),
enableETags: true,
enableJSMin: true,
enableYuiCSS: true,
skipMissingFiles: false,
enable304s: true
)>

<cfsavecontent variable="raw">
<cfset oCombine.combine(files=fileNames)>
</cfsavecontent>


<cfif cgi.HTTP_ACCEPT_ENCODING contains "gzip" AND not showRaw and Len(raw) GT 0>
<cfset bos = createObject("java","java.io.ByteArrayOutputStream") >
<cfset bos.init()>
<cfset gzipStream = createObject("java","java.util.zip.GZIPOutputStream")>
<cfset gzipStream.init(bos) >
<cfset gzipStream.write(raw.getBytes("iso-8859-1")) >
<cfset gzipStream.close()>
<cfset bos.flush()>
<cfset bos.close()>

<cfset encoder = createObject("java","sun.misc.BASE64Encoder")>
<cfset outStr= encoder.encode(bos.toByteArray())>
<cfset sOutput = toString(tobinary(outStr))>
<cfheader name="Content-Encoding" value="gzip" >
<cfheader name="Content-Length" value="#ArrayLen( sOutput.getBytes() )#" >
<cfoutput>#sOutput#</cfoutput>
<cfelse>
<cfoutput>#raw#</cfoutput>
</cfif>

Some notes:
You can use this for JS and/or CSS
notice i convert the result of combine into ISO before writing it to gzip. i think this was something i did to get around some strange problems with multi-lingual utf-8 content being coverted into base 64 encoding and back again.

Wednesday, November 11, 2009

cfobjective ANZ day1

long time no post :)

Been at cfobjective anz today and here is my wrap up of day 1

Keynote
Ben Forta down under! Nice preview of CF9 changes and CF Builder functions available. The main one for me was the licencing change for shared dev servers. This is new to me, but obviously not to everyone.

http://www.terrenceryan.com/blog/post.cfm/coldfusion-9-testing-staging-and-development-changes-to-eula

Social Apps with CF
Andy Welsh showed some funky framework using JQuery as the controller between CFC's and CFM views when retrieving data from social apps like Google / Flickr & Facebook.

One thing he seems to try and deal with caching of remote requests and instability in the results from facebook. its a bit scary to think that facebook is so unstable.

Im Slightly confused on its usefull ness - i think i need to read the code.

PDF Forms
Kai Koenig showed off some of the great stuf you can do with livecycle designer and coldfusion without forking out loads of money on live cycle ES.

It was great session in that it gave me an idea about using a PDF Form based workflow via email rather than sending URL's to people to go back to a website, regiser, then fill out a form. They just fill the form out and post the Form & its data back to the server directly from acrobat.

JVM Tuning
Mike Schierberl showed some tips about how to tackle a JVM memory issue with CF. I was hoping for a big checklest of JVM settings to play with, but he did give some good examples on how memory leaks can occour and how to avoid them. What i did see was hot to use some of the GC logging and memory analysing tools.

Seems i learnt alot of this stuff the hard way last week. See my CFAussie Post
http://groups.google.com/group/cfaussie/msg/c3ff3ed5e16785e8


Decentralised Version Control
Indy Nagpals presentation on Git and other decentralised version control tools was great. I had never heard of that before. I have a hard enough time getting all our code into SVN let alone moving to the next best ting.

git-svn looks cool as a way of working with git locally on an SVN project thats used across the team.

His talk on continuous integration was interesting to. The thing a took away there was the code needs to be 'testable code' before its worth making tests for it. So much for my 1999 vintage CF4 based code :(

Cascading View Inheritance
Geoff Bowers talking about farCry core and how its views work in an MVC setup.
havent looked at farCry in a while and the new caching stuff looks cool.
custom object types looks interesting too!