How do I Clear Cache on Startup?

0 favourites
  • 5 posts
From the Asset Store
Basics sprites and tilesets to build a platformer game or prototype
  • Hi everyone,

    How can I clear the browser cache on startup of my HTML game?

    The reason I need to do this is for runtime theming:

    if I want to replace my blue dart animation

    with a red dart animation

    (without having to re-export my game)

    I just overwrite the blue 1-7.png's with red 1-7.png's

    but I have to clear my browser's cache before this works.

    (don't clear cache = blue darts still)

    (do clear cache = red darts)

    Is there any way with the browser plugin or anything else

    that can allow me to make sure the game pulls from file every time?

    thank you for any input

  • The other two ways I thought about clearing the cache were:

    1. using the browser plugin to execute javascript to clear the cache

    2. somehow editing the exported index.html myself to clear the cache

    in either instance, the idea would be to add an http response header like this:

    Cache-Control: content="no-cache, no-store, must-revalidate"

    but how to do the syntax around this or where to do this I don't know

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I also tried to use the AJAX plugin with the Set Request Header Actions:

    but this did not work either, same thing happens:

    1. shows blue cached darts

    2. I clear browser cache

    3. shows red new darts

  • Construct has a system in place that updates the game if there's a new version. You circumvent this system by editing the exported project rather than exporting a new one.

    It's a shot in the wild and I haven't tested it but I do think it's possible to trigger this update system by simply editing offline.json (along with whatever other changes you made) and increasing the version number by one, then reloading twice. (First reload triggers the update that happens in the background, second reload then applies it)

    The functionality for this is a little bit hidden inside the Browser plugin.

    construct.net/en/make-games/manuals/construct-3/plugin-reference/browser

    construct.net/en/tutorials/offline-games-construct-8

  • The way updates are handled is described in the tutorial Offline games in Construct 3.

    As it notes there, offline.json must be re-uploaded with every change, as that file must change for Construct to download a new update.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)