Speed Tips: Remove Last-Modified Header

FREE THOUGHT · FREE SOFTWARE · FREE WORLD

Speed Tips: Remove Last-Modified Header

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

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!!


«
»

Leave your own comment

Reader Comments

  1. uggs ~

    Thanks. RTT time is a big part of little page loading time. i never thought about remove these two headers, but it really works, at least one round request and response saved.

  2. Google’s Need for Speed – Use Cache in .htaccess to Speed Up Your Site — Chicago Style SEO ~

    [...] which basically accomplish the same thing but don’t need to be used. As AskApache said in his fantastic posts on caching: If you remove the Last-Modified and ETag header, you will totally eliminate If-Modified-Since [...]

  3. sunnybear ~

    Information isn’t valid. Existence of Last-Modified / ETag doesn’t influence rate of cache integtiry checks in browsers

  4. Matt ~

    I love this tip. I’ve done a lot of optimization research and actually nobody ever suggested to remove the Last-Modified header and it’s interesting to know that the browser will not pass in those “If-” requests which is once again less bytes that have to travel across the web.

    My only question is why are you suggesting NOT to remove the Last-Modified header for .html files?

  5. Robot Terror ~

    This is what I currently have in my .htaccess file at the root. Do you see any problems with what I have here?

    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

  6. Spencer ~

    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…

    FileETag None
    Header unset ETag
    Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
    Header set Pragma "no-cache"
    Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
    
    Header unset ETag
    FileETag None
    
    SetOutputFilter DEFLATE
    
    Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
    
    Header unset Last-Modified
    

    Thanks for your help!

  7. Robot Terror ~

    BTW…auto-playing music is a good way to lose traffic. Is this a MySpace page?

  8. Robot Terror ~

    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.

Go for it!


It's very simple - you read the protocol and write the code. -Bill Joy

HTML | DCMI | GRDDL | XOXO | XDMP | XFN | DOM | XML | XHTML 1.1 Strict | CSS 2.1 | W3C

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution 3.0 License, just credit with a link.
This site is not supported or endorsed by The Apache Software Foundation (ASF). All software and documentation produced by The ASF is licensed. "Apache" is a trademark of The ASF. NCSA HTTPd.
UNIX ® is a registered Trademark of The Open Group. POSIX ® is a registered Trademark of The IEEE.

Site Map | Contact Webmaster | Glossary | License and Disclaimer | Terms of Service

↑ TOP
Main