Speed up website -Compress CSS/JavaScript using GZIP/DEFLATE compression – Optimization Tips -Part 2
In our previous discussion we checked the factors which influence the website load speed.(Read : 7 steps to Speed up website loading – Website Optimization Tips -Part 1).
Beginning with HTTP/1.1, web clients indicate support for compression with the accept-encoding header in the HTTP request.The web client can sent the following values as the accept-encoding header.
1 | Accept-Encoding: gzip, deflate |
Gzipping generally reduces the response size by about 70% and the result will be a faster and quicker web site.
Read: 7 steps to Speed up website loading – Website Optimization Tips -Part 1
Read: Check website/ web page for css/script Gzip/ Deflate compression
How do we achieve CSS or JavaScript compression?
The HTTP request header which indicates the encoding types is “Accept-Encoding: gzip, deflate”.
If the web server sees this header in the request, it may compress the response using one of the methods listed by the client.How do we achieve this?
Majority of the websites are hosted on Apache Web Server.The Apache server by default will not enable GZip compression. We have to manually achieve this by editing the .htaccess file.
First thing to check here is to find out whether your server supports mod_gzip or mod_deflate.if your server support this then you can add few lines of code to your .htaccess file which will enable the compression for you.
Usually you can find the .htaccess file in the root location of your web context. It is the httpdocs (/htdocs or /public_html) directory.If it does not exist create an .htaccess file and upload to that directory using an FTP tool like FileZilla.
As we discussed in our previous post the important thing to note here is that ,if you use Apache web server, the module configuring gzip depends on your version.
Apache version 1.3 uses mod_gzip but Apache 2.x uses mod_deflate.
How to use Mod_Deflate or DEFLATE method to support the GZip compression.
This is simple and straight forward.Just add the following line to the .htaccess file.
1 2 | # compress the files: AddOutputFilterByType DEFLATE text/html text/plain text/xml |
If you want to have additional types of files you add those to the end of the line as shown below.
1 2 | # compress the files: AddOutputFilterByType DEFLATE text/html text/plain text/css text/javascript application/x-javascript |
Using mod_gzip or GZIP method to support the GZip compression.
Apache version 1.3 uses mod_gzip and you should add a slightly different scripts to .htaccess file to achieve GZIP compression.
Copy and paste the following code to the .htaccess file.
1 2 3 4 5 6 7 8 9 10 | # gzip compression mod_gzip_on Yes mod_gzip_dechunk Yes mod_gzip_item_include file \.(html?|txt|css|js|php|pl|jpg|png|gif)$ mod_gzip_item_include handler ^cgi-script$ mod_gzip_item_include mime ^text/.* mod_gzip_item_include mime ^application/x-javascript.* mod_gzip_item_exclude mime ^image/.* mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.* |
Check the code once ,here you can include or exclude certain file types compression.
Now you can check the speed of your website and verify whether the CSS and script files are served using GZIP encoding or not.
Is there any utility available to check whether your website is optimized for Data compression using GZIP or INFLATE?
Read that Here:Check website/ web page for css/script Gzip/ Deflate compression
But what if your webserver has ZLIB enabled?
Some web servers supports ZLIB and it is enables for them.Here is the tip for those types of web servers.This is also an easy one, simply add the following to your .htaccess file
1 2 3 | # compress the files: php_flag zlib.output_compression On |
Static compression methods.
You can instruct the server to serve static zipped version of the script or css file, if it finds one, instead of the normal file.If you add the following line to .htaccess file the server will do just that.
1 2 3 | RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{REQUEST_FILENAME}.gz -f
RewriteRule ^(.+) $1.gz [L] |
Sign up or join Globinch on Social Media
Stay Connected
Follow globinch
Popular Posts
- Search Engines for File Sharing Sites : Rapidshare Search, Megaupload and More 6 comment(s) | 16258 view(s)
- Turn your Windows 7 Computer Into a Personal Wi-Fi Hotspot 15 comment(s) | 16117 view(s)
- Google Translate Now supports Bengali, Gujarati, Kannada, Tamil and Telugu 2 comment(s) | 15714 view(s)
- Google Top Searches Today – Hot Google Search Words today 12 comment(s) | 11559 view(s)
- Best PDF OCR Tools to Convert Scanned images to Text / Word Documents 20 comment(s) | 10154 view(s)
- Globinch Search 0 comment(s) | 8401 view(s)
- Access Blocked sites, Unblock Restricted Websites 15 comment(s) | 7310 view(s)
- Free Online OCR Software to Convert Images Into Searchable PDF, Doc, HTML or Text 3 comment(s) | 7238 view(s)
- Password Revealer – How To Reveal- Show Password Behind Asterisks? 7 comment(s) | 7180 view(s)
- Play Angry Birds Game Free and Offline in Chrome Browser 1 comment(s) | 7049 view(s)
Recent Articles
- Best Free Tools to Enlarge Images without Losing Quality
- How to Track Your Gmail Email and Schedule Gmail Mail Free?
- Google Webmaster Unnatural Links Detected Warning & Penalty
- How to Use Trial Software Version Forever Without Expire
- How to Use Folder as Drive or Convert Folder to Drive?
- Add Buttons, Message Boxes and Text Highlights in WordPress Post
- Top 20 Free WordPress Social Share Plugins
- rel=”shortlink” Short URL Indicator and Its WordPress Support
- Pagination SEO Using rel=”next” and rel=”prev” Link Attributes
- Watch Live IPL 2012 Season 5 Online on Your Computer or Mobile










Pingback: Check website/ web page for css/script Gzip/ Deflate compression - Optimization Tips -Part 3 | Globinch
Pingback: 7 steps to Speed up website loading - Website Optimization Tips | Globinch
Pingback: How to Test Your Website Completely - Validate HTML,CSS , RSS, ATOM,Mobile compatibility | Globinch
Pingback: How to Optimize Images for Blog and Websites. Top tips for Image optimization. | Globinch
Pingback: Minify JS (JavaScript) and CSS files to speed up your website. | Globinch
Pingback: Best PDF OCR Tools to Convert Scanned images to Text / Word Documents | Globinch
Pingback: Top 10 tips : Speed Up Blog and Blog Speed Test and Load Time | Globinch
Pingback: Website Performance Test From Different Geographical Locations | Globinch
Pingback: Google Closure Compiler to Minimize and Optimize JavaScript Online | Globinch
Pingback: JavaScript Minify: Best Tools to Minify JS and CSS | Globinch