Home >Web Front-end >JS Tutorial >About JavaScript's gzip static compression method_javascript tips
For a small website, reducing a page by 10KB is nothing, but for a large website, it adds up to a lot of traffic... gzip compression is an effective and feasible method, but it requires Apache Support (Apache and IIS share a port solution).
The compression rate provided by traditional JS compression (deleting comments, deleting extra spaces, etc.) is sometimes unsatisfactory. Fortunately, modern browsers support compressed transmission (by setting the Content-Encoding=gzip of the http header). You can pass The server configuration (such as apache) provides compressed transmission for your js, or the GZipFilter used in appfuse allows tomcat to also provide this capability
The problem now is that this dynamic compression will cause the CPU usage to be too high. Now The solution I think of is to provide static compression (that is, js is pre-compressed through gzip.exe)
1. The application in tomcat is described below
1. Convert prototype.js Compress and save to prototype.gzjs through gzip.exe 2. Set header, I wrote a simple AddHeadersFilter to add all files ending with gzjs and set header Content-Encoding=gzip configuration in web.xml