You are not logged in. Please login or register.
Web Hosting » Support » NuBlue » Web Hosting » Utilising Gzip Compression - Shared
Utilising Gzip Compression - Shared
Shared Hosting : Utilising Gzip Compression
Overview
Gzip compression is a quick and simple method of speeding up page load times for visitors to your site. Its very simple, rather than send the browser a 100k file with the html (or css or javascript) for a page its quicker to compress the page on the server, send the compressed data, then have the browser uncompress it. Trust me it is, even with broadband connections it is still expensive in terms of resources to transmit data to the end user.
There is an overhead involved with compressing data on the fly, it increases the cpu load on the server (or vps), however I can say with some authority that cpu overhead is not currently an issue for any of our servers nor for any of our VPS customers, so the slack is there to be picked up and used to improve page loading times.
Complexity
Easy (Though it does have the potential to break your site if things go wrong its very easy to revert back)
Suitable for:
Shared Hosting - Almost any site, with the possible exception of Interspire sites as its already there!
(For VPS and Dedicated hosting there is a slightly different method that is much more efficient, see here)
Although its possible that this will conflict the Fooman Speedster for Magento as everything else does.
Requirements
Access to your Hosting Control Panel.
Alternatively FTP Access to your site and an FTP Client that allows you to view files starting with . (or hidden files as they're sometimes called). We recommend the Filezilla FTP client.
Howto :
As ever Nublue recommends that you backup your entire site using your Hosting Control Panel backup utility before undertaking any significant changes to your site. In this instance we're only going to edit one file, so if you're feeling confident you could just make sure you have a copy of your current .htaccess file (if it exists) that you can revert back to if things go awry.
1) Check whether your site is already gzip compression or not. Entering your home page at this site will tell you whether your html files are being compressed. You should also examine your page source and extract a URL for a css or javascript file and check whether these types of files are being compressed. If your pages are already being compressed it may be worth continuing anyway as there are two methods of compression (Apache based and PHP based, the Apache method is more efficient and its worth swapping if you're currently using the PHP method). If your data is not being compressed then we know what we need to do.
2) In your Hosting Control Panel navigate to your web root in File Manager (Login -> Home -> your_domain_name.com -> File Manager -> httpdocs). Here look for a file named .htaccess(You may need to click the All on the right to stop pagination). If the file doesn't exist then you can jump straight to Step 3. If it does exist then now is a good time to make a copy of the .htaccess file.
2.1) Select your .htaccess file, then click on the Copy/Move option :

2.2) Choose a name for the copy of your .htaccess (I've chosen .htaccess_bk) and append it to directory path already in the textbox (/httpdocs/). Click the Copy button. You now have a backup of your .htaccess file.

2.3) Now open the file for editing : Click the pencil icon in the middle of the .htaccess row.
2.4) Check for the following words, these are all indications that compression is setup, you have the choice here of leaving as is, or commenting out the existing lines and replacing them with the code in Step 4 to see if there's an improvement:
AddOutputFilterByType
SetOutputFilter
php_flag zlib.output_compression on
<IfModule mod_deflate.c>
Pay close attention to whether these rules are active (for example a default Magento .htaccess file contains all these entries, but all of them are commented out or inactive).
3) Creating a .htaccess file : To create a new .htaccess file click on Add New File.
3.1) In the dialogue boxes set Create New File to selected, enter the filename .htaccess and ensure Use html template is unticked then click OK. This will create the file and automatically open it for editing.

4) If the file already exists the append the following code to the bottom of the file (For new files simply paste the code in) :
<IfModule mod_deflate.c> AddOutputFilterByType DEFLATE text/html AddOutputFilterByType DEFLATE text/plain AddOutputFilterByType DEFLATE text/xml AddOutputFilterByType DEFLATE text/css AddOutputFilterByType DEFLATE text/javascript AddOutputFilterByType DEFLATE application/x-javascript </IfModule>
Then save the file with the default settings (UTF-8 and convert to Unix style).
Thats it, now test your site again at Gzip compression testing site mentioned at the start of the article.
Possible Issues :
If all your pages stop working then it will be one of three things:
1) A typo : Recheck your .htaccess file (its still open for editing), try removing and readding the code.
2) A conflict : Some web apps may use per page PHP code to compress their pages and these could conflict with the configuration changes we've made to the .htaccess. Remove the code we added.
Reversing the Change
Delete the newly created/edited .htaccess : Select the file then press Remove Selected and Confirm.
Rename your .htaccess_bk (you did make one right?) using the frankly bizarre File Rename that sits alongside the pencil icon.
Or restore from your backup.
Further Reading
This article does a very good job of explaining how gzip compression works and also links out to other useful articles.
Web Hosting » Support » NuBlue » Web Hosting » Utilising Gzip Compression - Shared







