Home > ColdFusion, JavaScript, Scriptaculous > Fix for Safari and gzip compressed javascripts

Fix for Safari and gzip compressed javascripts

April 2nd, 2009

Yesterday I showed how to use cgi.HTTP_USER_AGENT to not push gzipped javascripts to IE6. After fixing that guess who starts choking? IE’s bastard stepchild: Safari. I don’t trust Safari any more than I do IE. Unfortunately my client base uses it all the time: Designers!

After some digging around I learned that you cannot send compressed javascripts to Safari with the extension of “gz”. It must be “jgz”. Steve, you have got to be kidding me.

So here it is fixed… notice the modified filename in the Content-Disposition:

<cfif cgi.HTTP_ACCEPT_ENCODING contains "gzip" and cgi.HTTP_USER_AGENT does not contain 'MSIE 6.0; Windows'>
	<cfheader name="Content-Encoding" value="gzip" >
	<cfheader name="Content-Disposition" value="inline; filename=""protoaculous182min.jgz""">
	<cfheader name="Content-Type" value="application/x-javascript; charset=ISO-8859-1">
	<cfcontent deletefile="no" file="#expandpath('./protoaculous182min.gz')#" type="application/x-javascript; charset=ISO-8859-1">
<cfelse>
	<cfheader name="Content-Disposition" value="inline; filename=""protoaculous182min.js""">
	<cfheader name="Content-Type" value="application/x-javascript; charset=ISO-8859-1">
	<cfinclude template="protoaculous182min.js">
</cfif>

Work flawless in Safari3, IE6, IE7, IE8, and Firefox3.

ColdFusion, JavaScript, Scriptaculous , , , , , , , ,

  1. April 2nd, 2009 at 08:45 | #1

    Thanks for the tip. I could never get gzip to work with Safari and couldn’t muster the commitment level to figure out why, so I just gave up on gzipping. I’ll have to revisit this when I have the time.

  2. April 2nd, 2009 at 13:29 | #2

    @Dominic O’Connor
    Same here! Over two years now on my own site I excluded Safari from getting the compressed version.
    This time I HAD to fix the problem because it was on a client’s site. Inspiration :)

  3. fDD
    April 10th, 2009 at 15:11 | #3

    FANTASTIC!

  4. chewie
    August 6th, 2009 at 02:05 | #4

    gzip and Safari…
    “After some digging around I learned that you cannot send compressed javascripts to Safari with the extension of ‘gz’, It must be ‘jgz’”
    Wow, that’s completely untrue. I run an Apache server that sends compressed files: javascript, css, json, html and xhtml are all compressed with gzip and work flawlessly.
    You must have a problem somewhere else on your server.
    IE8 on the other hand cannot display compressed css with headers that work in IE7 and every other browser.

  5. August 6th, 2009 at 13:17 | #5

    @chewie
    It could be server related. 99% of my work is on Windows servers (IIS).
    For portability then, it’s probably best to use jgz.

  1. No trackbacks yet.