Fix for Safari and gzip compressed javascripts

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.

5 thoughts on “Fix for Safari and gzip compressed javascripts”

  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. 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.

Comments are closed.