If you remove the Last-Modified and ETag header, you will totally eliminate If-Modified-Since and If-None-Match requests and their 304 Not Modified Responses, so a file will stay cached without checking for updates until the Expires header indicates new content is available!
Easy Apache Speed Tips Articles
- Turn On Compression
- Add Future Expires Header
- Add Cache-Control Headers
- Turn Off ETags
- Remove Last-Modified Header
- Use Multiple SubDomains
Please don’t turn off ETags and Last-Modified headers for your .html files, leave one of them ON. (I use Last-Modified for .html).
Remove Last-Modified Header
This goes in your root .htaccess file but if you have access to httpd.conf that is better.
This code uses the FilesMatch directive and the Header directive to remove all Last-Modified Headers from being sent.
<FilesMatch "\\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css)$"> Header unset Last-Modified </FilesMatch>
How it Works
By removing both the ETag header and the Last-Modified headers from your static files (images, javascript, css) browsers and caches will not be able to validate the cached version of the file vs. the real version. By also including a Cache-Control header and Expires header, you can specify that certain files be cached for a certain period of time, and you magically (this is a really unique trick I promise) eliminate any validation requests!!
htaccess last-modified header apache validate expires cache
Related Articles
12.03.07 at 12:06 am
Yes, this will speed individual requests, but for those sites with actual traffic they may crawl to a halt due to re-requested content from frequent visitors (think RSS feeds) and spiderbots (Google, etc.). It’s a trade-off that massive scalable systems must consider: slow each request a little to be able to serve all requests reasonably fast.
12.03.07 at 12:07 am
BTW…auto-playing music is a good way to lose traffic. Is this a MySpace page?
12.14.07 at 2:23 am
[...] Remove Last-Modified Header [...]
04.29.08 at 12:36 am
This is what I currently have in my .htaccess file at the root. Do you see any problems with what I have here? Would you organize it differently? I don’t know much about .htaccess files, but would love to see if this is ok for my server. Here it is below…
Thanks for your help!
04.29.08 at 3:41 pm
First off, once your rules are correct be sure to move the rules out of .htaccess and into the httpd.conf file for the Directory section of your DocumentRoot. Why? .htaccess is inherently slow as it must be read for each and every request that starts in or goes deeper than the directory in which it resides (and for which AllowOverride is enabled).
See the Apache documentation for .htaccess files for more information