123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|529|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Web Development -> Caching Issues

Sun, 12 Jan 2020, 05:23
Jayenkai

Caching Issues


Gawd, what a couple of days I've just had..

Shoebox and Browsercade made use of AppCache to ensure everything's cached for Offline play.
A simple list of files that get saved to the AppCache.
If you update any files on the server, simply update the cache.manifest file, and browsers will notice the change, then re-download everything as required..

Easy as pi.
And it works absolutely flawlessly.

Which is really fucking frustrating when W3C decide that AppCache isn't good enough, design a new method (Service Workers), and then for whatever reason, decide to kill off AppCache.

In April, most of the Chrome-based browsers will be removing AppCache functionality, so pretty much all my hard work has been in vain.

Gone.. Broken.. Any webapp still using AppCache is screwed..

-=-=-

So, Service Workers, then. Convoluted and insanely overly complicated.
I tried my best to understand this stuff, but documentation is either stupidly vague, or overly code-garbled with "really" useful things like the word "cache" being used in multiple instances, for multiple purposes, and just really not well written at all.

I eventually wound up adding a library from here. UpUp handles most things needed to replace AppCache, and it works .. OK..
Both Shoebox and Browsercade now make use of Service Workers and should (*should!) work both off and online as expected.
As always, let me know if they don't.

-=-=-

And now, the new problem.
The new method has a slight flaw with caching, in that (as far as I can tell from reading a LOT of stuff online) the cache will 100% refuse to update any images or sounds for around about 24 hours.
Meaning, if someone visits Shoebox on a Sunday Night, I upload a game Monday Morning, the game code will be available, but any new sprites will NOT be updated.
So if the new game uses a new sprite graphic, the spritesheet won't update, but the game will load, so the new sprite will.. simply.. not appear in the game.

For 24 hours..

And this isn't "Service Workers" doing, either. This is a base browser functionality.
The Service Worker is definitely saying "Get the update". I can see it doing the request. But the browser's own cache is saying "No.. You did that 23.5 hours ago. You can use the old one."

Meaning, from here onwards, I need to upload any new art and sounds at least a day before I upload the game.. And since sounds are usually the last thing I do when coding a game, that means I need to have games ready a day before release.
Fuxake..

The simple "traditional" way to avoid this would be to add "?Timestamp=nnnn" to the URLs of the images, which works fine when online, but offline usage confuses the Service Worker enough that none of the bloody images show up at all.

Another alternative would be to rename the files after an update, but the way the Service Worker cache works, this would end up clogging the user's cache up with hundreds of similar .pngs with varying filenames.


So... No luck..
If anyone knows of any other way to force an image/sound/data cache update.. Do let me know! Thanks!

-=-=-
''Load, Next List!''
Sun, 12 Jan 2020, 11:52
Jayenkai
OK, that's the 24 hours up..
Why the fuck is Edge still not updating!?
For the love of god, this is absolutely shitting well ridiculous..

-=-=-
''Load, Next List!''
Sun, 12 Jan 2020, 14:39
Jayenkai
OK, I *think* I've solved the issue.
The solution is a little* bit counter-intuitive, but that's because all of this is completely dumb. So, you know.. Gonna be like that!!


In order to cache the files correctly, you need to open .htaccess, and tell the browser NOT to cache the files... AT ALL..


.... Yes, that is actually the apparent solution to this whole mess.

What's happening is that, when offline, the Service Workers say "OK, let's use the ones from the Service Worker cache", and that's ok.
But when we're online, and there's an updated image, the Service Worker says "OK, let's use the new version from the network."
The Service Worker asks the browser to fetch the file, and the browser goes "It's alright, I've got a copy here!", offers up the old cached version (not the new one) and then the whole thing never gets update.

Now, if you add some "No-Cache EVER" rules to your .htaccess, then the browser doesn't keep it's own stash, and the only version left is the version that the Service Worker puts away for itself, which IS Cached, even though you told it not to cache things....

Now when we're offline, sorted, easy access to the stashed away Service Worker cache, and that works fine.
When we're online, Service Worker asks the browser to fetch, the browser has no cached version, so the browser does as it's told and fetches the new version.

From all that I've managed to test, tonight, that appears to be working just fine.
I'll need to double check in the morning, in case it's decided to do something stupidly different, which ... I'll be honest.. It's managed to baffle me in a fair number of ways, today, so I'm not discounting that!

Oh boy...


* A lot.. Very.. Extremely. Insanely..

-=-=-
''Load, Next List!''