Prevent caching of dynamic (php) content

2019-06-11 23:32发布

I've attempted to set up appropriate caching, however I'm having trouble getting the dynamic portions through.

You can see the site in question here: nathanhornby.com And the repo here: https://github.com/nathanhornby/nathanhornby.com

As you'll see there are 3 feeds at the bottom. The issue is that if you load up the page now, it seems to be cached, and therefore every time you load it you'll see the exact same content, requiring a user force-refresh to see the new content, which is naturally impractical.

** Note: ** I'm talking about the page caching, not the feed caching. The feeds do cache, this is intentional, but if the feed changes this is only reflected if the user refreshed. The 'time ago' is the same. If it said '9 minutes ago' the first time you load it, it'll say the same thing the next time you load it. But refreshing the page will update that time.

You can see my .htaccess setup here: https://github.com/nathanhornby/nathanhornby.com/blob/master/.htaccess

I would hope that this section does what I need, but it doesn't seem to:

# Disable Caching for PHP <FilesMatch "\.(pl|php|cgi|spl|scgi|fcgi)$"> Header unset Cache-Control </FilesMatch>

What's the best way to ensure that fresh content is served on load, without the need for a refresh?

1条回答
Animai°情兽
2楼-- · 2019-06-12 00:00

Your saying that you want fresh content without a page refresh. For that you will need something else such as JQuery and AJAX, disabling caching won't make pages update themselfs without refresh.

Is this what your looking for?

 <FilesMatch "\.(pl|php|cgi|spl|scgi|fcgi)$">
    FileETag None
    <ifModule mod_headers.c>
        Header unset ETag
        Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
        Header set Pragma "no-cache"
        Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
    </ifModule>
 </FilesMatch>

Source: http://www.askapache.com/htaccess/using-http-headers-with-htaccess.html

查看更多
登录 后发表回答