How to set up ETag with browser caching

Ive configured the browser cache for a static site via a file .htaccessby setting:

# BROWER CACHING - 1 Day for images
<filesMatch ".(jpg|jpeg|gif|ico)$">
Header set Cache-Control "max-age=86400, public"
</filesMatch>

Im fine with these images having a 1 day cache, but the site changes often and therefore I don't want to cache CSS and JS files.

Ive read about ETag, which, as I understand it, allows you to cache the file, but also set the creation date, so if it is updated the next time the client visits the site, it will check if the creation date matches.

  • Did I understand ETag correctly?
  • How to configure it? Ive looked around, but could not find any information about his configuration.
+4
source share
4 answers

FileETag MTime Size, Header unset Etag FileEtag none. (Create ETag Remove ETag) , .

# Create the ETag (entity tag) response header field
FileETag MTime Size

# Remove the ETag (entity tag) response header field
Header unset ETag
FileETag none
+2

ETags - , , , , 2 ETags (, URI), , . Last-Modified.

Last-Modified , 1 , (, ) , ETags . , , ETags , .

ETag If-None-Match GET If-Match PUT, , ETag (s) ETag ( ), ( PUT PATCH) , .

ETag Last-Modified . . , , . , , , .

(Expires header max-age Cache-Control ) , , , ( ). , .

+2

ETAG . , , . 100% , etag. http://pisrs.si. ? Hit F12 , , , , . localhost -. .

, . , .

<IfModule mod_mime.c>
    AddType text/css .css
    AddType application/x-javascript .js
    AddType image/bmp .bmp
    AddType image/gif .gif
    AddType application/x-gzip .gz .gzip
    AddType image/x-icon .ico
    AddType image/jpeg .jpg .jpeg .jpe
    AddType image/png .png
    AddType application/x-font-ttf .ttf .ttc
    AddType application/zip .zip
</IfModule>
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType text/css A31536000
    ExpiresByType application/x-javascript A31536000
    ExpiresByType application/javascript A31536000
    ExpiresByType text/javascript A31536000
    ExpiresByType text/x-js A31536000
    ExpiresByType image/bmp A31536000
    ExpiresByType image/gif A31536000
    ExpiresByType application/x-gzip A31536000
    ExpiresByType image/x-icon A31536000
    ExpiresByType image/jpeg A31536000
    ExpiresByType application/x-font-otf A31536000
    ExpiresByType image/png A31536000
    ExpiresByType application/x-font-ttf A31536000
    ExpiresByType application/zip A31536000
</IfModule>
<IfModule mod_deflate.c>
    <IfModule mod_headers.c>
        Header append Vary User-Agent env=!dont-vary
    </IfModule>
        AddOutputFilterByType DEFLATE text/html text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/plain image/x-icon image/png image/gif
    <IfModule mod_mime.c>
        # DEFLATE by extension
        AddOutputFilter DEFLATE js css htm html xml png gif
    </IfModule>
</IfModule>
<FilesMatch "\.(gif|ico|jpg|jpeg|png|GIF|ICO|JPG|JPEG|PNG|css|js|woff|CSS|JS|WOFF|ttf|TTF)$">
    <IfModule mod_headers.c>
         Header unset Set-Cookie
         Header set Cache-Control "max-age=31536000, public"
    </IfModule>
</FilesMatch>
+1

HTTP , , (), ( , - -, ). : expiration ( ) ( ).

Entity tag (ETag) . - (Last-Modified). Entity - . . , :

  • ETag , .

  • ( ETag).

  • , , . If-None-Match, .

  • ( If-None-Match ), , ( ), 304 Not Modified , .

( CGI script , ) Apache ETag FileETag. , , Apache ETag, (mtime) Apache 2.4. Apache 2.3.14 inode.

, Apache ETag, , , . script ETag If-None-Match. . mod_perl If-None-Match Apache2:: Request:: meets_conditions, HTTP/1.1 .

ETag, . Cache-Control: max-age=0, must-revalidate Expires: 0, (.. ). Last-Modified , HTTP/1.1 .

Last-Modified ETag . :

, Last-Modified HTTP/1.0. ETag ( If-None-Match If-Modified-Since).

As an additional note, Id would like to add that the proposed RFC 7232 standard exists and is associated with the details of entity tags and conditional requests. See Appendix A for the changes it introduces from HTTP / 1.1 .

-1
source

All Articles