Prevent Apache to cache html5 manifest

2019-06-25 17:16发布

This is probably really easy to solve, I've checked on stackoverflow but I did not find anything:

I have WAMP Installed with PHP and Apache, running the latest version of the Laravel successfully.

I have a cache.manifest file, it is loading correctly however it doesn't seem to refresh even if I change its content.

So I tried a few things I found, including:

AddType text/cache-manifest .manifest
<IfModule mod_rewrite.c>
   Options -MultiViews
   RewriteEngine On
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteRule ^ index.php [L]
</IfModule>
<FilesMatch "\.manifest$">
   Header set Cache-Control "max-age=259200, proxy-revalidate"
</FilesMatch>

When I add the FilesMatch section, I always get an Internal Server Error

What could I do to prevent ONLY the cache.manifest file to be cached? I have also tried other things with FileMatch but it fails everytime (I had that kind of code for images (png gif...) for example and it didn't work.

Thank you for your help.

标签: html5 caching
2条回答
叛逆
2楼-- · 2019-06-25 17:42

Use an expire by type

The AddType statement is already present to ensure that manifest files have the right mime-type. This can be used to specify appropriate cache headers:

ExpiresByType text/cache-manifest "access plus 0 seconds"

This and more useful information is available in the html5 boilerplate htaccess file.

查看更多
淡お忘
3楼-- · 2019-06-25 17:48

Another solution is to use PHP, because according to HTML5 specification the extension of the cache-manifest file is not matter:

<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header('Content-Type: text/cache-manifest');
//your content below out of PHP tag
?>
CACHE MANIFEST

Then you can use:

<html manifest="manifest.php">
查看更多
登录 后发表回答