Windows Server 2003
(1)
IIS 6.0
(1)
IIS
(1)
StaticFileHandler
(1)
Firefox
(1)
Firebug
(1)
Oops
(1)
Javascript
(1)

Using gzipped javascript files

Asked By \(O\)enone
04-Jul-07 04:17 AM
Hello,

I've read in numerous web sites that I should be able to gzip my javascript
files in order to reduce the amount of data transfer required to get them
from my web server (running IIS6 in Windows Server 2003) to my web browser.

Despite trying all sorts of things, I've been unable to get this to work.
Could someone help point me in the right direction?

I have taken my original javascript source file (mycode.js) and gzipped it
to produce mycode.js.gz. I then change the script tag in my HTML page from:


(which works fine) to reference the gzip file instead:


At this point, the script stops working.

If I look at the network transfer using Firebug in Firefox, I can see that
the .gz file was successfully downloaded. The request headers include
application/x-gzip". The file is obviously being interpreted directly in its
compressed form (I can see from the Firebug errors the raw data from the .gz
file is being displayed with an "Illegal character" error) rather than being
decompressed first.

Is this because I am delivering a file whose content type is
content type in "text/javascript" and whose encoding is "gzip"? If so, how
can I configure my IIS server to respond in this way?

Many thanks,

--

(O)enone

Using gzipped javascript files

Asked By Andrew Morton
04-Jul-07 06:43 AM
You don't do anything - it should happen automatically: see
http://www.webreference.com/internet/software/servers/http/compression/

in particular note the section titled "Is Compression Built into the
Browser?"

Andrew

Hi,I belive you enable compression on the webserver and not create these files

Asked By Kristofer Gafvert
04-Jul-07 04:06 PM
Hi,

I belive you enable compression on the webserver and not create these
files yourself.


http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/25d2170b-09c0-45fd-8da4-898cf9a7d568.mspx?mfr=true

http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/502ef631-3695-4616-b268-cbe7cf1351ce.mspx?mfr=true

Just be aware of some compatible issues with older browser (i think i
remember there are some problems, not sure though right now).

--
Regards,
Kristofer Gafvert
http://www.gafvert.info/iis/ - IIS Related Info

Using gzipped javascript files

Asked By David Wang
04-Jul-07 06:01 PM
All you need to do is:
0. Do not pre-compress any content you want IIS to transfer with HTTP
compression
1. Make sure .js extension is processed as a static file in the vdir
that the .js file is located
2. Enable static file compression in IIS
3. Make sure .js is in the list of extensions that static file
compression applies to
4. Have client make accept-encoding: gzip,deflate request to retrieve
the .js file from the vdir

Yes, your current problem is what you describe -- the web browser
script engine only knows to deal with tetx/javascript, so the desired
sequence is NOT "plainly transport compressed entity over HTTP and
force script engine to decompress prior to execution" but rather
and send plain entity to script engine". The former is "private
communication of compressed content". The latter is "HTTP
Compression". Web browsers understand the latter, not former.

FYI: People usually have problems correctly performing steps #1 and
because it sometimes affects the distinction between "static file" and
handled by the IIS StaticFileHandler". Anything else is NOT a "static
file".

For example:
1. .txt file without application mapping and has content-type is
considered static file
2. .txt file with wildcard mapping and has content-type is considered
dynamic file
3. .asp file without application mapping and does not have content-
type is a static file that cannot be downloaded
4. .asp with application mapping and does not have content-type is a
dynamic file

People see .txt and assume #1, .asp and assume #4, but when they
customize web server processing #2 and #3 become possible... and
confusion can result. For example, substitute .log for .asp, or .xml
for .txt.


//David
http://w3-4u.blogspot.com
http://blogs.msdn.com/David.Wang
//
Using gzipped javascript files
Asked By Andrew Morton
05-Jul-07 04:52 AM
Oops - my mistake. As Kristofer points out, you have to enable it on IIS.

Andrew
Post Question To EggHeadCafe