Bug 162700 - HTML files w/ localStorage being cached when running off file system
Summary: HTML files w/ localStorage being cached when running off file system
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: History (show other bugs)
Version: Safari 10
Hardware: Mac OS X 10.11
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-09-28 13:35 PDT by Sean Michael
Modified: 2016-09-28 21:51 PDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sean Michael 2016-09-28 13:35:01 PDT
I am experiencing difficulty with Safari 10 running html files off of the file system.  I do not run into this issue when running these files off of a server.

I am using JavaScript to set a value in localStorage on a button click with `localStorage.setItem('plan', index);` and then immediately redirecting the user with `window.location.href`.  When landing on the new page, I use `localStorage.getItem('plan');` to render corresponding data that is based on the 'plan' value.  When using all other modern browsers this works perfectly.  When running Safari 10 (11602.1.50.0.10) this only works correctly the first time you click the button and set the plan item in localStorage.  If I return to the original page and select a different button, which sets a different plan item, it will always revert to the first selected plan item.

I dug deep into this issue and have discovered that it is an issue with Safari cache.  When disabling cache or clearing cache, my button click will set the correct plan item (as expected) and not used cached localStorage.  I tried adding `meta http-equiv='expires' content='0'` tags to the head of my html files, but it still seems to cache the first localStorage value that was set.  I also tried adding query strings to the url's in the redirect, but this doesn't bust the cache either.  If I open a new tab or new window, the cache is not shared, so I am able to correctly select an item.  The odd part of this bug is that this does not occur when I run the html files off of a server, it only happens on the file system.  It does not occur in the newest versions of Chrome or FireFox for Mac either.
Comment 1 Alexey Proskuryakov 2016-09-28 21:51:09 PDT
Thank you for the report!

Could you please share a small reproducible case for easy testing?