Whenever you visit a website you will almost certainly recieve compressed
.xml files. This because they are very compressible, over 90%, which saves bandwidth and speeds up load times.
However, they’re compressed by the webserver every time they are served. This is a waste of CPU cycles and places extra load on both the webserver and the client. The anser is to compress all of these files once on the server and serve the pre-compressed files.
a2enmod deflate headers configtest
Next you need to create the Apache2 configuration which will:
- Serve pre-compressed
.xmlfiles if they exist.
- Avoid re-compressing the pre-compressed files.
Open a new configuration file at
And copy and past the following code:
Thanks to the Apache Documentation for help with the code.
You should always verify your Apache2 configuration before restarting the webserver because bad config will stop Apache2 from starting:
# apachectl configtest Syntax OK
Finally, you need to comperss your
.xml. Something like the following will work:
find <PATH THE SITE CONTENT> -type f | grep -e ".html$" -e ".css$" -e ".xml$" -e ".js$" | xargs gzip -9 -k