简体   繁体   English

提供压缩的javascript文件

[英]serve zipped javascript file

I join all my external javascript files into one file. 我将所有外部javascript文件合并为一个文件。 I make two version of this file. 我为此文件制作了两个版本。 One is zipped, one is not. 一个是拉链,一个不是。 How to check the browser support gzip or not and serving a right file? 如何检查浏览器是否支持gzip并提供正确的文件? And if browser support gzip, how to tell it this is a zipped file? 如果浏览器支持gzip,如何分辨这是一个压缩文件?

Is not required to zip JavaScript file, 不需要压缩JavaScript文件,
instead, you should use mod_deflate 相反,您应该使用mod_deflate

Apache will handle the compression and detect clients browser support gzip header. Apache将处理压缩并检测客户端浏览器支持的gzip标头。
If the clients browser support the gzip header, a compressed copy of JavaScript will be sent. 如果客户端浏览器支持gzip标头,则将发送JavaScript的压缩副本。

You can also explicitly set an expiration header for static files to better leverage on browser cache. 您还可以显式设置静态文件的到期标头,以更好地利用浏览器缓存。

Normally when your browser requests a page, it sends information on the content types/encodings it can accept, including (if applicable) whether it can accept gzipped content. 通常,当您的浏览器请求页面时,它会发送有关其可以接受的内容类型/编码的信息,包括(如果适用)是否可以接受压缩的内容。 So, you can check the header (I think it's the Accept-encoding header) to see if it has gzip in it. 因此,您可以检查标头(我认为这是“ Accept-encoding标头)以查看其中是否包含gzip。

Though, I'm pretty sure that the server handles this (checking for compression support and compressing files) itself if you set it up correctly. 但是,我很确定如果设置正确,服务器会自行处理(检查压缩支持和压缩文件)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM