0

As far as i know it's impossible to achieve the following, but only an expert can confirm this:

I've got page number 1 that request for some user and application data as soon as the page loads, page number 2 uses the same script and it would be wasteful to request for the same info.

I know that the browsers caches the script, my question is if it caches the execution (data) as well.

The pages don't share the same layout, so it is not possible to make page number 2 be reloaded via ajax.

1
  • 1
    Browsers don't (and really can't) cache results; it doesn't really make much sense in general. You could however put the results of some computation in a cookie or in local storage in the browser. Commented Mar 26, 2012 at 14:06

4 Answers 4

2

The browser doesn't automatically cache the result of the script (that would be seriously weird), but you can, by setting (and checking for) cookies, using the new local storage stuff on modern browser, etc. Note with cookies, though, that they're sent to the server on every request, so result in increased size of requests; if you can use local storage, do.

Sign up to request clarification or add additional context in comments.

2 Comments

I would not recommend cookies here, as they are transmitted at every future request. Depending on the shape of the data to store, this may result in quite some unnecessary traffic.
@Sirko: I'd say we don't have enough information to know whether they're an appropriate choice or not -- but it's a good point to reinforce for the OP.
1

You can "cache" your data, if you use some kind of client side storage like localStorage (see MDN docu for more details).

The Browser itself may also cache your request internally as the ajax request is no different from any other request made by the browser (html docs, images, etc.). So depending on your exact request (including all parameters) the Browser may actually use a cached version of your request to avoid unnecessary calls. Here, however, the usual restrictions and properties of caching apply, so you can not rely on that behaviour!

Comments

1

Browser will not cache your data automatically if your "page" is a new URL.

But it is certainly possible for you to implement it in several ways One is to use local storage in new browsers that support HTML5

Another is to write your app such that it is a single page with multiple views and transitions Use AJAX to replace portions of your page (views).

This technique is becoming increasingly popular.

I highly recommend reading "Javascript Web Applications" by Alex MacCaw to understand javascript MVC and how to use javascript to create a client side (browser based) controller and views and manage caching, state etc in the browser. Also look at frameworks like backbone.js

http://www.amazon.com/JavaScript-Web-Applications-Alex-MacCaw/dp/144930351X/ref=sr_1_1?s=books&ie=UTF8&qid=1332771002&sr=1-1

Comments

1

I would avoid caching the data, except if there's serious performance problems (and, then, rather eliminate the performance problems than caching it). It's premature optimization.

When having the data cached, all kind of scenarios (stale data, deleted data) must be considered (except if the data is static, but then, it's not relevant anyways).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.