News:

Want to get involved in developing SMF? Why not lend a hand on our GitHub!

Main Menu

.htaccess no cache

Started by Krashsite, October 01, 2013, 12:27:52 AM

Previous topic - Next topic

Sir Osis of Liver



Running a script with a countdown timer that shows time remaining in month.  There's a 'Help' button that loads a FAQ in same window, and using 'Back' button in window, or browser back, causes timer to revert to where it was when previous page opened, so it's no longer accurate.  Tried an old trick I used several years ago to address a similar problem, and it works in IE and FF.

.htaccess -



# NEVER CACHE
<FilesMatch "\.(php)$">
Header set Cache-Control "max-age=0, private, no-store, no-cache, must-revalidate"
</FilesMatch>



Any idea how reliable this is?

When in Emor, do as the Snamors.
                              - D. Lister

Arantor

Why not just have the PHP script itself manage its own caching headers? SMF does when it's appropriate with a header() line which looks a bit similar to yours ;)

Doing it for the entire server's worth of PHP files is probably not the smartest idea in the world, though...
Holder of controversial views, all of which my own.


Sir Osis of Liver

I've tried using caching headers in the past, and didn't have much luck.  IIRC, they were browser dependent, worked in some, not in others.

All of the files involved are in the same directory as .htaccess, so it should only affect files in that directory ("\.(php)$"), which is what I'm trying to accomplish.

When in Emor, do as the Snamors.
                              - D. Lister

Arantor

If you didn't have much luck with caching headers in the past, why would it work now?

All I'm suggesting is for you to do the same thing your .htaccess file would do only not using .htaccess ;)

The thing about .htaccess files is that they have a habit of spreading. Typically they will apply to any folder below them as well, and if this is in the same folder as your forum... it also screws up all the forum caching too...
Holder of controversial views, all of which my own.


Sir Osis of Liver

Quote from: Arantor on October 01, 2013, 05:11:04 AM
If you didn't have much luck with caching headers in the past, why would it work now?

Well, that was my point.  The headers didn't work reliably, but .htaccess did.

There are no folders below the one I'm working with (except an image folder), so affecting anything downstream is not a concern.  The folder containing this .htaccess is in the forum root, at the same level as Themes, Sources, etc.

When in Emor, do as the Snamors.
                              - D. Lister

Arantor

So that means they weren't added in PHP properly.

But the folder containing this .htaccess file... is the forum root? So you're applying that caching to EVERY PART of the forum, seeing how everything in the forum is routed through index.php in that folder... Congratulations for breaking SMF's caching (which is quite capable of doing exactly what you're trying to do, search for headers() calls and has been working successfully for a decade)
Holder of controversial views, all of which my own.


Sir Osis of Liver

Quote from: Arantor on October 01, 2013, 06:46:46 PM
So that means they weren't added in PHP properly.

Yes, very likely, but .htaccess solved the original problem without having to edit every file, so there was no reason to change anything else.

Quote
But the folder containing this .htaccess file... is the forum root?

It's not in the forum root, it's in a folder that's in the forum root, and should affect files only in that folder and below.

Like this -

  www.domain.com/forum/index.php

  www.domain.com/forum/folder/.htaccess

Also shouldn't affect SMF caching (which I usually disable anyway).

When in Emor, do as the Snamors.
                              - D. Lister

Arantor

QuoteAlso shouldn't affect SMF caching (which I usually disable anyway).

If only I were actually talking about the same thing, which I'm not. The caching headers sent by SMF cannot be turned off (and even if they couldn't they shouldn't be)...

As for the folder location, my bad, I misinterpreted what you said because it wasn't actually clear what you meant.
Holder of controversial views, all of which my own.


Sir Osis of Liver

There's a server setting in SMF for caching, which is what I was referring to.  I've had problems several times in different contexts with persistent files that would not update when changed, and continue to load even after being deleted from server.  There's browser cache, server cache, flash cache, and apps such as SMF with their own cache, .... 

Caching has caused me much over the years.

When in Emor, do as the Snamors.
                              - D. Lister

Arantor

Which is not the same as caching headers which SMF does output as well as everything else. Though I'm not sure why you have trouble with caching; works just fine for me.
Holder of controversial views, all of which my own.


Advertisement: