The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 18, 2019, 01:14:14 PM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: gzipped JS  (Read 4763 times)
nop_90
Global Moderator
Lifer
*****
Offline Offline

Posts: 2203


View Profile
« on: June 05, 2007, 11:56:58 PM »

has anyone used this ?
<script type="text/javascript" src="prototype.js.gz"></script>

this guy claims it works in all major browser except safari
Logged
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #1 on: June 06, 2007, 08:53:05 AM »

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

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
JasonD
Expert
****
Offline Offline

Posts: 100


View Profile
« Reply #2 on: June 06, 2007, 02:21:48 PM »

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
Logged
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #3 on: June 06, 2007, 02:30:00 PM »

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)?
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
nop_90
Global Moderator
Lifer
*****
Offline Offline

Posts: 2203


View Profile
« Reply #4 on: June 06, 2007, 04:42:50 PM »

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 Smiley

http://joseph.randomnetworks.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 .....

Logged
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #5 on: June 07, 2007, 08:43:01 AM »

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
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
nop_90
Global Moderator
Lifer
*****
Offline Offline

Posts: 2203


View Profile
« Reply #6 on: June 07, 2007, 04:19:48 PM »

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.
Logged
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #7 on: June 07, 2007, 09:41:21 PM »

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

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
nop_90
Global Moderator
Lifer
*****
Offline Offline

Posts: 2203


View Profile
« Reply #8 on: June 08, 2007, 01:00:27 AM »

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")
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
Logged
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!