.HTACCESS doubts(special mod_expires)

Asked

Viewed 553 times

1

I would like to better understand how this module works, in particular I leave as an example what is in the Root folder of one of the sites I handle:

<IfModule mod_expires.c>
ExpiresActive On 
ExpiresDefault "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType text/css "access 1 month"
ExpiresByType application/javascript "access plus 1 year"
</IfModule>
  • the part ExpiresDefault sets the default expiration of all items(gif, png, css, js..) ?
  • So on my.htaccess I am overwriting the default value that was previously defined (when I set expire to png, jpeg.. specifically) ?
  • If I start the mod_expires . htaccess module in a subfolder, same empty, it overwrites what was written in the . htaccess module which stays in the root folder?
  • It is true that if I use parameters in the URL, I will be forcing caching again, for example, this: index.html, be different from that index.html?1234?

1 answer

1

the Expiresdefault part sets the default expiration of all items(gif, png, css, js..) ?

  • Not only of gif, jpeg, png, but of any page accessed, even the dynamics. However you can use <FilesMatch> to filter the files you want to receive the ExpiresDefault, see this example:

    #Qualquer página terá um cache de 1 mês
    ExpiresDefault "access plus 1 month"
    
    #Arquivos que tem extensão como .gif, .jpg, .jpeg e .png terão um cache de 1 ano
    #Sobrescreve o primeiro
    <FilesMatch "\.(?i:gif|jpe?g|png)$">
        ExpiresDefault "access plus 1 year"
    </FilesMatch>
    

So in my . htaccess I am overwriting the default value that was set earlier (when I set expire to png, jpeg.. specifically) ?

  • Yes, ExpiresByType over to the page that uses the specified mimetype.

If I start the mod_expires . htaccess module in a subfolder, even empty, it overwrites what was written in the . htaccess which gets in the root folder?

  • Yes, the. htaccess of subfolders "screams" the parameters and flags of the top-level folders.

Is it true that if I use parameters in the URL, I will be forcing caching again, for example, this: index.html, is it different from index.html? 1234?

  • It is true, because for the browsers index.html is different from index.html?1234, For all that comes after ? is a GET parameter and means that you are looking for something supposedly different, the browser has no way of knowing if index.html is a static or dynamic page, and we usually use ? to define that we are looking for something dynamic. It is very common to use the ? to prevent caching of .js and .css.

    See this answer: What is it for and when to use version in . js and . css files?

    Note that some servers proxy do not interpret ? and so in some cases the cache is not ignored.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.