9

and to tell browser to reload an object (and/or a page... everything on the site) only if is been modified since last visit time??? htaccess, httpd.conf... have you a ready directive right for my case? Thank You very much

smepie
  • 193
  • 1
  • 1
  • 3

2 Answers2

7

html5boilerplate.com includes a well commented .htaccess file that has many standard settings you should consider. Among them are reasonable settings for expiring the content (Expires, E-tags, ...).

Here's the documentation on mod_expires.

brclz
  • 103
  • 4
matthew
  • 1,309
  • 1
  • 11
  • 21
5

Note that Last-Modified headers are weak cache headers. The current preference is to use Cache-Control headers.

Google has a good article on this.

Optimize Caching

Expires and Cache-Control: max-age. These specify the “freshness lifetime” of a resource, that is, the time period during which the browser can use the cached resource without checking to see if a new version is available from the web server. They are "strong caching headers" that apply unconditionally; that is, once they're set and the resource is downloaded, the browser will not issue any GET requests for the resource until the expiry date or maximum age is reached.

Last-Modified and ETag. These specify some characteristic about the resource that the browser checks to determine if the files are the same. In the Last-Modified header, this is always a date. In the ETag header, this can be any value that uniquely identifies a resource (file versions or content hashes are typical). Last-Modified is a "weak" caching header in that the browser applies a heuristic to determine whether to fetch the item from cache or not. (The heuristics are different among different browsers.) However, these headers allow the browser to efficiently update its cached resources by issuing conditional GET requests when the user explicitly reloads the page. Conditional GETs don't return the full response unless the resource has changed at the server, and thus have lower latency than full GETs.

I recommend using either Cache-Control or Expires headers as needed since they are strong cache headers. Some systems will ignore Last-Modified dates.

You can then use a tool like curl or http://redbot.org to check the headers.

jeffatrackaid
  • 4,112
  • 18
  • 22
  • 2
    FWIW: "weak" is something that Google made up. `Expires` is a totally inappropriate header for resources that do not expire. Some resources may be modified, but not at some expiration date. Google's point is that `Last-Modified` requires a conditional GET, whereas `Expires` allows the browser cache to skip the GET altogether. – Dancrumb Jul 29 '14 at 18:14
  • 1
    The term *weak* is simply semantics. The point is that using `Last-Modified` headers in the absence of other caching instructions leaves the cache period up to the HTTP client. If a resource has not been modified since the `Last-Modified` date, the resource should be considered fresh. In contrast, when using an `Expires` or `Cache-Control` header the origin can set an explicit freshness period. – jeffatrackaid Jul 29 '14 at 19:51
  • 1
    "weak" v "strong" is defined at https://tools.ietf.org/html/rfc7232#section-2.1 (Note also to @Dancrumb) – John Bentley Jun 24 '15 at 20:08