简体   繁体   中英

Enable Gzip compression for javascript hosted on other server

We have a website say 'abc.com' which uses lot of javascript and css hosted on another server 'xyz.com'. We upload js and css on to this server and it gives us a URL, which we use/reference in our code.

Now I ran YSLOW on my website, and it complains that these javascript and css files can be compressed. When I inspect response headers using firebug, Content Encoding of response is set to 'GZip'.

My question would be 'how to enable compression for these javascript and css files, hosted on other server'. Is there something, we can do on our side?

Any suggestions are welcome.

You will have to use tools like YUI compressor to compress your js and css files, before uploading to the server.

EDIT:

Please check this link on how to enable gzipping your js and css files . But, I doubt it is possible for you to do this since the files are hosted on third server(unless you are managing it).

JavaScript and CSS compression goes beyond typical all-purpose compression algorithms like gzip.

There are domain specific solution for compressing JavaScript and CSS.

See:

To clarify the terminology used by YSlow (and similar tools like Google's PageSpeed):

Compression reduces response times by reducing the size of the HTTP response. Gzip is the most popular and effective compression method currently available and generally reduces the response size by about 70%. Approximately 90% of today's Internet traffic travels through browsers that claim to support gzip.

Minification removes unnecessary characters from a file to reduce its size, thereby improving load times. When a file is minified, comments and unneeded white space characters (space, newline, and tab) are removed. This improves response time since the size of the download files is reduced.

Some good references that cover both compression and minification:

As robert mentioned in his answer, enabling compression on the other server would be a configuration change on that side. If you wanted to minify the JS/CSS components, you could do that with a minification tool prior to hosting on the other server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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