2

I have a site for download files (.pdf, .rar, .jpg,...). I have a big problem with server and I think it related to apache:

For example i linked to 12.pdf for download it:

<a href="12.pdf">book</a>

It works fine but problem: I changed 12.pdf with another file with same name. When downloaded new 12.pdf, Previous file is downloaded. Even I remove 12.pdf from server and press Ctrl+F5 in my page, When clicked on above link, 12.pdf download start and file download completely!! Whereas not exist file with 12.pdf name on server. What is problem? Does apache cache my links? How solve this problem? My server OS is CentOS.

mr.soroush
  • 1,110
  • 2
  • 14
  • 31

1 Answers1

7

Some solutions, in no particular order, that might help.

  1. Create a Hash:

    A better approach is to modify the file path (or name) by introducing a hash which will change when the file is modified; then in the apache configuration you can strip that value to get the right file path (or name). See here: https://developers.google.com/speed/docs/best-practices/caching?hl=es-419#LeverageBrowserCaching

    via http://www.immense.net/force-update-cached-files-images-favicon/#comment-18489

  2. Server Headers. The caching can also be control on the server side based on the response headers.

    For example, to force the file to be cached for no longer than 1 day, you would send:

    Cache-Control: max-age=86400, must-revalidate 
    

    For beta, if you want to force the user to always get the latest, you would use:

    Cache-Control: no-cache, must-revalidate
    

    via https://stackoverflow.com/a/84846/1085891

  3. Use a GET variable. Add a version number, or any value for that matter, which will force the browser to pull the latest file. Example:

    <a href="12.pdf?ver=1.1">book</a>
    

    Many do not recommend this technique for any file that may require caching at some point (CSS, JavaScript, etc.).

  4. <FilesMatch> directive

    Include the .htaccess lines in a <FilesMatch> directive. For example, these lines will prevent caching of filenames ending in ".htm" or ".html", while allowing normal caching of JPEG files:

    <FilesMatch "\.(htm|html)$">
      ExpiresActive On
      ExpiresDefault A1
      Header append Cache-Control must-revalidate
    </FilesMatch>
    

    via http://support.tigertech.net/prevent-caching

Resources

Community
  • 1
  • 1
JSuar
  • 21,056
  • 4
  • 39
  • 83