snippetMinor
Suggestions on how to improve this .htaccess file for page load speed
Viewed 0 times
thisfilehtaccessimproveforpagehowsuggestionsloadspeed
Problem
Here is my standard .htaccess file, any suggestions on how I can improve it with regards to page load speed? Would gZip instead of DEFLATE make any sort of difference?
ExpiresActive On
RewriteEngine on
RewriteBase /
# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
# Expires 1 month after file is first accessed
ExpiresByType image/jpeg A2592000
ExpiresByType image/jpg A2592000
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/x-icon A2592000
ExpiresByType text/plain A2592000
# Expires 1 month after file is modified
ExpiresByType application/x-javascript M2592000
ExpiresByType text/css M2592000
ExpiresByType text/javascript M2592000
ExpiresByType text/html M2592000Solution
Honestly, this looks OK, though you could clean it up a little bit.
You have two ways to make this code better:
Regarding point #2, here's part of the config I created after watching Illya Grigorik's presentation "Breaking the 1000ms Time to Glass Mobile Barrier":
You might also look into Google's mod_pagespeed for Apache.
You have two ways to make this code better:
- group related mime types.
- use human-readable syntax
Regarding point #2, here's part of the config I created after watching Illya Grigorik's presentation "Breaking the 1000ms Time to Glass Mobile Barrier":
# these are known to be safe with MSIE 6
AddOutputFilterByType DEFLATE text/html text/plain text/xml
# everything else may cause problems with MSIE 6
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/x-javascript application/javascript application/ecmascript
AddOutputFilterByType DEFLATE application/rss+xml
ExpiresActive On
ExpiresDefault "access plus 15 minutes"
ExpiresByType text/html "access"
ExpiresByType application/json "access"
ExpiresByType text/css "access plus 1 week"
ExpiresByType image/gif "access plus 1 week"
ExpiresByType image/png "access plus 1 week"
ExpiresByType image/jpeg "access plus 1 week"
ExpiresByType application/javascript "access plus 1 week"
You might also look into Google's mod_pagespeed for Apache.
Code Snippets
<IfModule mod_deflate.c>
# these are known to be safe with MSIE 6
AddOutputFilterByType DEFLATE text/html text/plain text/xml
# everything else may cause problems with MSIE 6
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/x-javascript application/javascript application/ecmascript
AddOutputFilterByType DEFLATE application/rss+xml
ExpiresActive On
ExpiresDefault "access plus 15 minutes"
ExpiresByType text/html "access"
ExpiresByType application/json "access"
ExpiresByType text/css "access plus 1 week"
ExpiresByType image/gif "access plus 1 week"
ExpiresByType image/png "access plus 1 week"
ExpiresByType image/jpeg "access plus 1 week"
ExpiresByType application/javascript "access plus 1 week"
</IfModule>Context
StackExchange Code Review Q#4812, answer score: 3
Revisions (0)
No revisions yet.