Section 2.41. Frequently Asked Questions?


2.41. Frequently Asked Questions?

Q:

Can't I just turn off caching in my browser, and avoid all this extra code?

A:

No, most of the options you have in your browser control caching of pages you directly load, by either typing a URL in the address bar or clicking a hyperlink on a web page. The requests that your JavaScript make are behind the scenes, and IE and Opera don't give you much control over how they handle those requests.

And even if you could turn off caching, many of your users will still have caching on in their browser. So you've got to work around caching, even if you can turn it off on your own web browser.

Q:

So just by sticking that "dummy" parameter on the end, I can get around caching?

A:

It's more than just the parameter, or the name of the parameter. It's changing the request URL itself. We used the name "dummy" to make it clear that the parameter isn't pointing to any data that's important to the application, but you could use any name for the parameter that you wanted to.

Q:

Won't there still be a problem if two requests are made within the same minute? The time would be the same for both requests then, right?

A:

No, getTime() returns the time elapsed since January 1st, 1970, and it returns that time in milliseconds. So unless you can manage to click "Show Me the Money" twice in the same millisecond, the r equest URL will be different each time.

Q:

What happens to the dummy parameter when the PHP script receives the request?

A:

Nothing. The PHP script doesn't need that parameter, so it just ignores it.

Q:

So now we just need to make this same change to getCustomerInfo() in pizza.html?

A:

That's not a bad idea... is it? Turn the page and let's talk about that some more.

I don't think we don't need to worry about caching in the Break Neck app. If the phone number is different, the request URL will be different. And if it's the same phone number, we don't need fresh data from the server; the customer's address is the same each time.

2.41.1. Good thinking!

You don't always need to worry about caching. In the Break Neck app, the request URL will be unique for each phone number, so there won't be any caching problems there.

If a customer enters the same phone number, caching probably would keep the request from going to the Break Neck server... but in that case, the server really would be returning the same customer datathe customer's address each time. So in that situation, caching actually saves your customer's time.

Be sure you don't end up adding code that you don't need to your applications. In the Break Neck app, there's no need to make any changes to the code you've already got.

This means we're done with Step 4! On to Step 5...




Head Rush Ajax
Head Rush Ajax (Head First)
ISBN: 0596102259
EAN: 2147483647
Year: 2004
Pages: 241

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net