Note that there are some explanatory texts on larger screens.

plurals
  1. POFragment Caching Using Javascript
    text
    copied!<p>Can someone point me to some example code on how best to do caching while loading up the dynamic parts of a page using javascript?</p> <p>My canonical example involves a page where nothing ever changes other than the user's logged in status and username at the top of the page. Changing this text through jQuery and an ajax request is easy enough, but since I'm doing it on <code>$(document).ready()</code>, if you look quickly, you can see the page load with something like "Click Here to Login" before the ajax request fires and updates that section of the page.</p> <p><strong>Edit for clarification</strong>:</p> <p>If I cache the entire page, the following happens.</p> <ol> <li>User A requests the page</li> <li>Page <strong>is not cached</strong>, so application generates html with "Hi User A" in the upper right corner</li> <li>User B requests the page</li> <li>Page <strong>is cached</strong>, so application serves it us as-is -- including the "Hi User A" bit &lt;- This is the part that I want to dynamically update.</li> </ol> <p>Ideally, at step 2, the page would get cached without the "Hi User A" bit, so that when someone requests the page, I make a simple ajax request to get the greeting and then shove it into the dom.</p> <p>I'm assuming javascript is the way to go, but I'm thinking there has to be a better way than to wait for <code>$(document).ready()</code> such that the page renders more naturally.</p> <p>If it matters (though I don't think it should, as a solution that applies to static html would also work for what I'm doing), I'm using rails 2.3.x and jQuery.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload