views:

30

answers:

2

I'm using .NET and the simple question is:

How or can I let the web browser know that

<script type="text/javascript" src="/Scripts/myjsfile.js"/>

is gzipped?

can I just append .gz to the source?

This article, which is pretty cool, shows how to to compress my dynamic html by plugging into the Response.Filter stream object to return gzipped content. But my css/js isn't dynamic so I don't see the point in wasting cpu cycles to zip for every single request.

So how do I tell the web browser that it's zipped content, or does it already know?

A: 

Tag response with header:

Content-Encoding: gzip

UPDATE: I just realised I answered your literal question - how the client will know - but not what you need to do on the server to make it send such. Unfortunately, I don't work with IIS, so I can't give you a smart answer.

If no-one answers you, you can do dynamic thing yourself, and it's not much slower. The thing that basically Apache is doing is this:

  • It tests whether the request's Accept-Encoding header includes gzip.
  • If it does, then checks if there is filename + ".gz" file
  • If it does, send that, tagging it with Content-Encoding: gzip and appropriate Content-Type
  • If not, check if there is filename, send that if it exists
  • If that fails, 404.

You can also tell it to gzip files on the fly; that's more economical in space, as you don't keep two versions of the file on the disk, but slower (because you need to compress at each request).

Amadan
A: 
#####################################################
# CONFIGURE media caching
#
Header unset ETag
FileETag None
<FilesMatch "(?i)^.*\.(ico|flv|jpg|jpeg|png|gif|js|css)$">
Header unset Last-Modified
Header set Expires "Fri, 21 Dec 2012 00:00:00 GMT"
Header set Cache-Control "public, no-transform"
</FilesMatch>
#
#####################################################

Change the "FilesMatch" to whatever you want gzipped. The server will automatically compress your uncompressed files to a gzip, send it to the browser and the browser will unzip the file back to it's original form.

Taylor Satula