javascript - How Gzip in Tomcat works -


i doing issues script compression. following found in stackoverflow:

"if using in webpage, gzip configuration method in web server. file gzipped server, sent browser. no manual action needed. apache: http://httpd.apache.org/docs/2.0/mod/mod_deflate.html.

if delivering code developers, use gzip command."

someone told me if such script compression strategy used, make easy debug:

when use firebug debug javascript in run time, script see original, uncompressed one, readable.

but if use yui compressor, script shown in firebug this:

var is_moz=(typeof document.implementation.createdocument!="undefined");var is_chrome=navigator.useragent.tolowercase().indexof("chrome")>-1;var selectedtreenodeidinoper="";var selectedtreenodepkinoper="";var windef="width=490,height=190,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,copyh.... 

which in horizontal line , hard read.

my question how can gzip in tomcat send compressed scripts clients meanwhile show developer original script? magic?

there's 2 separate issues going on here: compression , minification.

compression process server compresses content (html,css,js) send client (browser). browser de-compresses content before got compressed. time view-source or @ developer tools in browser you're seeing original script. think of sending zip file someone. original file still there was, wrapped in zip.

compression can enabled in several places in app's architecture. can enable in webserver (you linked apache's httpd docs), app server (tomcat supports compression) or in own code (search 'servlet compression filter' examples)

minification (which yui compressor , other tools do) permanently changes script, creating -min.js version of file. file missing newlines , may have variables re-named. because altered file server sending, that's you'll see in browser , yes, it's hard debug. browser makers have recognized , chrome, firefox , ie11+ support sourcemaps tell browser how map minimized version of code original file. yui compressor doesn't support sourcemaps, other tools uglify do.

you can use minification , compression , there benefits doing so. see this discussion more detail.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -