iOS Web App - how to deal with overzealous app caching?

后端 未结 1 1168
盖世英雄少女心
盖世英雄少女心 2021-02-05 12:56

I\'ve been developing a pretty complicated HTML5 web app for the past month. Last night my iPhone suddenly decided to cache all JS, CSS, and images an

相关标签:
1条回答
  • 2021-02-05 13:07

    For what it's worth, and it's not a perfect solution, we had to settle with appending query strings. I've written a shell script to make this and a few other tasks bit more automated, you can look at the source on GitHub. A few details:

    • It's designed for JS but can easily be edited to handle CSS too.
    • It takes all files listed in script_order.txt and compiles them with Google's Closure Compiler
    • Groups them into chunks under 25kb when possible (iPhone won't cache anything over 25kb pre-gzip, although apparently this extends only to browsers and not standalone webapps)
    • Outputs a PHP file with <script> tags that have a ?v=timestamp appended to the script filenames. If you're working with static HTML and can't include a PHP file, you could rewrite the output to append the script tags to your index.html file.

    Another pretty hacky solution would be to save your JS/CSS with a .php file extension, and in those files set the headers to something like this:

    <?php
    header("content-type: application/javascript");
    header('Cache-Control: no-cache');
    header('Pragma: no-cache');
    ?>
    window.alert('hello world');
    

    EDIT:

    Setting the date to 2, 3 or 4 days in the future, start the app from homescreen and then set the date back to normal also can do the trick.

    0 讨论(0)
提交回复
热议问题