Search code examples
javascriptweb-storage

Storing value in js across page reloads


I was searching for an answer here and found that it an be accomplished through webstorage and cookies. However, I also came across this interesting post:

Do browsers parse javascript on every page load?

It says: "Chrome 42 introduces an advanced technique of storing a local copy of the compiled code, so that when the user returns to the page the downloading, parsing, and compiling steps can all be skipped. Across all page loads, this allows Chrome to avoid about 40% of compile time and saves precious battery on mobile devices."

Does it mean that values of variables will be persistent across page reloads? For eg. if I am storing the color selected by the user in a variable, then will that value be available in that variable after another page (on same domain) is loaded?

P.S: I could not comment there as I am a newbie and don't have enough reputation required for commenting on answers.


Solution

  • No, it does not mean variables are stored, or that HTML suddenly has state, it only means Chrome stores the parsed scripts internally so they don't have to be downloaded and parsed again.

    This is just an internal optimization to make Chrome faster, not something you have acccess to, you'll still need persistent storage, like cookies, local storage or the server.