Thread: gzipped JS
nop_90

has anyone used this ?
<script type="text/

javascript

 " src="prototype.js.gz"></script>

this guy claims it works in all major browser except safari

perkiset

quote author=nop_90 link=topic=295.msg1978#msg1978 date=1181113018

has anyone used this ?
<script type="text/

javascript

 " src="prototype.js.gz"></script>

this guy claims it works in all major browser except safari


Hey bro - post the url of the article... - this example would point to either that the browser DOES pay attention to the suffix on a url for code (which would mean that you should be able to do .

php

 .gz or whatever) or that, by default, everything coming in is automatically checked to see if it is compressed. The headers coming to the server should include whether or not the HTML can be compressed, so I guess this is worth looking at for JS...

JasonD

As long as the MIME type is set correctly on the server all modern browsers will automatically download, decompress and parse any GZipped file.

It's exactly how mod_gzip and equivalent for IIS works. MIME based, not extension based

perkiset

Any opinion on where best to do the compression JD?
I've seen arguments for using

Apache

 , using

PHP

  and against both

SMF has a simple switch to turn it on/off... I'm gonna take a look at how they chose to do it...

if I read you correctly, then simply gzipping a a JS file on the server side should grant a reasonable increase in throughput/decrease in bandwidth... but you hint at "modern" browsers... in that case, should all JS be stored as BOTH and then look at the

Apache

  to see if the browser can handle it, and dispatch appropriately? Or perhaps have all requests for JS go into a

PHP

  script that sets the "encrypt-ok" switch (have to look that one up), pull up the JS file and return it (which would either encode or not)?

nop_90

woops sorry i thought i added the link to origional reference.
This is what happens when u do like 6 things at once.
Probably some adult affiliate is wondering why am i sending him an email with a link to JS compression Applause

http://joseph.rando

mnet

 works.com/archives/2006/07/13/compressed-

javascript

 /
he said it works on
<>I’ve tested this on Firefox 1.5 and IE 6 on Windows; Firefox 2, Opera 9 and Safari 2.0.3 on

Mac

  OS X. Before you get too excited there is one problem, this doesn’t work on Safari. All of the browsers that I tested showed no difference between gzip and non-gzip

JavaScript

  except for Safari.

but then jason hints that mime type has to be set on the server.
maybe be concidence his server had the mime type set .....

perkiset

In his article he talks about simply compressing files and avoiding the

Apache

  mods_ for compressed output... I'm thinking that this is a mistake, since

Apache

  would know to compress or not based on the browser's headers. Or, you'd do it in

php

  and look at the headers.

I'm going to have to look at the headers and see if, when Safari makes a request, it says that compression is OK for JS - that could be the problem. I'm just thinking off the cuff here, but perhaps mod_rewrite could be employed to see if "compressed" is available to the browser, and if so, return a compressed version of the JS else return the uncompressed version. You could even look to see if there IS a compressed version in the target directory, and if not, don't even do the mod_rewrite ie., you could write this as a module that sits in all virtual hosts and passes down compressed output only when the browser is OK with it and the file actually exists

nop_90

quote
In his article he talks about simply compressing files and avoiding the

Apache

  mods_ for compressed output... I'm thinking that this is a mistake, since

Apache

  would know to compress or not based on the browser's headers. Or, you'd do it in

php

  and look at the headers.


I was thinking more along the lines where you do not have control of the server.
so do a browser detect like this
http://www.quirksmode.org/js/detect.html

and then change how you load the JS file depending on browser.

perkiset

Ummm yeah... but if the

javascript

  is alread out at the client (to detect the browser ala quirksmode), then the pull has already been made and therefore you're *post* the need to compress... which is why it needs to be at the

Apache

  or server language point in the transaction I think...

nop_90

quote
Ummm yeah... but if the

javascript

  is alread out at the client (to detect the browser ala quirksmode), then the pull has already been made and therefore you're *post* the need to compress... which is why it needs to be at the

Apache

  or server language point in the transaction I think...

i do this all the time

you can do stuff like document.write('<link rel="stylesheet" type="text/css" href="XXXX"Applause
and it will include the file in XXXX

so maybe you could do a document.write to include the appropriate js file
not sure if it works with <script> tags hmmmm


Perkiset's Place Home   Politics @ Perkiset's