Editing The htaccess file
As a result of these simple, quick tweaks, my “PageSpeed” and “ySlow” scores have all bumped up as well. They were already pretty good, but I’m constantly trying to optimize for speed and every little bit helps. Especially as more and more users connect to the web over mobile.
The biggest impact can be made simply be adding a few lines to your htaccess file. This file is located inside your site’s “root” directory. Here’s how I edit my file via my site’s cpanel application:
- First, once you login to cpanel, look under the “Files” panel and click on the “File Manager” icon. A popup screen will appear like so:
- Once you’ve checked the “Show Hidden Files (dotfiles) checkbox, click “Go”.
- You will then be presented with your files listing. It looks like this:
- From there, you just highlight the .htaccess file and click “Edit” from the top toolbar. Here’s what the contents of that file should look like when you are done:
So, as you can see from the screenshot above, to address Google PageSpeed/ySlow nags for “Specify a cache validator“, gZip Compression, Expires headers and eTags, I’ve added the following to the top of my htaccess files on all my demo sites:
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xhtml+xml
ExpiresDefault "access plus 1 year"
Header unset ETag
After applying those settings and updating your htaccess file on your server, you should be all set. However, if, after several hours, the tools are still reporting that your files are not compressed, The next step should help…