Jump to content

Strange Browser Cache issue with Safari IOS


FrancisChung
 Share

Recommended Posts

Hi there,

I'm experiencing a real weird caching issue with Safari (Desktop) and all mobile browsers where it is loading the old version of the site and refusing to reload the website.

I don't seem to have the problem with Chrome where a reload did correctly reload the latest version of the website.

Has anyone come across this issue before?

 

Things I have tried (and failed) :

1) I've replaced our .htaccess file with the standard one that comes with Processswire 2.8

2) Everything here
https://stackoverflow.com/questions/1922910/force-browser-to-clear-cache

3) Deleted everything under /assets/pwpc folder. 

4) Deleted all local wesbite data on laptop/mobile and reloaded.

Much appreciate if anyone can help me 

Link to comment
Share on other sites

Do you have template cache enabled? When you're logged in on your PC, you wont notice anything, because cache will be disabled but visiting the page as guest on an iOS device you might be getting a cached version with the old content and old URLs.

Although I see you've tried using query strings, I often use this function to create cache busting URLs for CSS & JS. If the file is modified, correct modified time string is appended to the URL and browser downloads newer version. No need to increment version manually.

/**
 * Adds file modified date as query string and returns URL to given asset.
 * 
 *
 * @param $relPath string File path relative to /site/templates/, such as "assets/css/style.css"
 * @return string URL with cache busting query parameter
 */
function assetUrl($relPath)
{
    $fullPath = wire()->config->paths->templates . $relPath;
    $modified = filemtime($fullPath);

    $url = wire()->config->urls->templates . $relPath . "?v=$modified";
    return $url;
}

In your templates, you can load a script like so:

<script src="<?= assetUrl("assets/js/main.js") ?>"></script>

 

  • Like 3
Link to comment
Share on other sites

Is it possible to use Pagefile class independent of a Page or Pagefiles class? Looking at Pagefile::__constructor, it needs both $page and $pagefiles to instantiate. I guess they're limited to internal use only. Probably because they're saved in DB

Link to comment
Share on other sites


Hi @abdus, I wasn't aware there was built in caching capabilities outside of Procache.

I've checked it now and alas it is off. I'm also a Procache subscriber but have turned that functionality off too.

 

But your comment about template caching somehow inspired me to try connecting to the index.php directly, and that seems to fixed the problem (?!?!)

Now Safari and all mobile browsers are loading normally, per normal without having to reference the index.php directly. I have no idea why that has fixed it.

 

I've checked the DirectoryIndex section of .htaccess file, and it's exactly the same as the the default Processwire file.

Thanks a lot for your cache busting script. Will incorporate it probably at the next release as a backup plan for such scenarios.
 

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...