title: Understanding PHP caching - what happens to JavaScript? - using Symfony2
body: <p>I'm trying to understand PHP caching. I'm using Symfony 2 and trying to get something together.</p>
  
  <p>Image a gateway cache or reverse proxy cache that caches the full page. How does JavaScript get affected by this?</p>
  
  <p>So imagine you had a page that rarely changed (maybe once a week) - you could probably cache it for a week. But imagine you had a JavaScript function that did something on that page, say a collapsible script. Imagine by default the HTML shows all panels open, and the JS remembers a value in local storage and after page load it closes the panels that need to (remembering the state). How would this affect caching?</p>
  
  <p>So for me the best way would be that only the HTML is cached and then the JS gets executed afterward anyway (and no doubt the JS files are already cached). Or does it sort of take a screenshot and if the page is cached with half the collapsible panels open and half closed then they will always look like that (until the cache is cleared).</p>
  
  <p>I'm trying to work out if ESI is better, or how I should create something so as to be able to utilise caching but still keep certain dynamic features. The best way would be to cache all HTML and allow the JS, CSS and everything else to run again from the cached JS/CSS file, whatever that is.</p>