Jump to content

Recommended Posts

Hello - sincerely hoping someone out there will be able to help with this, or at least have a good idea on what's going on.

I have created a 'Single Page Application' (SPA) type website, and have used PHP on the server-side.  At present, nearly all my content files (XML, JPEGs, XSLT, CSS) are generated from PHP scripts.

My design uses many source files, and some pages have many small images, so file caching by the client browser is very important.  I have set HTTP Cache-Control response headers on everything, to inform the browser that it can and should cache everything.  (Content changes get picked up when a version number changes in the URL.)  So far, so good - or so I thought.

My problem is that both Safari and Chrome on iOS do fresh requests of EVERYTHING that's come from PHP, every time the user opens the phone from screen-lock.  So the site is fast and slick with everything loaded into cache, until a 20 second pause with the phone locked, and then everything is dog slow again the first time content is viewed.  For my use-case, this is a huge usability (and server load) problem.

I've noticed that this refreshing of content DOESN'T happen for regular static files.  (I have a folder of static file PNG images, and these never get re-requested.)  How can I make all the PHP-generated content appear to the browser to be static files, so that the browser's heuristics don't mistrust them and assume they will be changing despite the HTTP headers?????!

I can't believe I'm having this problem, honestly. Never seen anything like it before, with browsers ignoring these Cache-Control directives.  There's something really messed up with the logic on mobile devices....

Edited by MartinPeck

This isn't directly related to your question, but you should consider using cloudflare that will give you a free CDN/Edge cache for your site, increasing performance and saving you bandwidth.

Going to assume that your app is using PHP Sessions.  If so, you need to review this setting as a first step.

The only other thing I can suggest is that in a case like this, is that hopefully you have a mac, and can use a cable to connect to the phone and use the safari develop menu. I'd also likely open a tail on the server so I can see the requests coming into the server.  You certainly want to question your assumptions as to what is happening as the app runs.  

The typical complaint in regards to safari is not lack of caching but the opposite -- aggressive caching that makes it hard to unload/clear the cache when developing/testing.  Your server environment is also an essential component with different options that can be used to configure the server (apache/nginx/etc) in how it handles different types of files.

  • 2 weeks later...
Posted (edited)

I realised I should add…. I have actually also established that this is unlikely to be a php (or more generally a ‘dynamically created content’) issue.

I tried converting some of my files into statically generated files, ie nothing to do with PHP.  My XSL files were still not cached by the browser properly.

So this issue right now actually seems unrelated to PHP.  It’s some kind of inconsistency between browsers’ treatment of different file types.

Edited by MartinPeck

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.