Make Ajax cacheable

I need some help please ,How can I make Ajax cacheable?.

Thank you in advance.

OK, I’m being dense, but why would you want to do that? The very basic concept of AJAX is to load new content dynamically without forcing a full page reload.

Or am I missing a critical piece of the puzzle here? Perhaps with more details, we can help you better.

@DaveMaxwell, I just read it from here

Best Practices for Speeding Up Your Web Site

And the answer is right there too (Add an Expires or a Cache-Control Header)

@DaveMaxwell, But I am confuse how to code that ?by the way can I set expiration time 1 day?..

Thank you in advance.

It’s in the calling page you’re trying to cache. If the page is php, it would be something like this:

<?php
  //set headers to NOT cache a page
  header("Cache-Control: no-cache, must-revalidate"); //HTTP 1.1
  header("Pragma: no-cache"); //HTTP 1.0
  header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past

  //or, if you DO want a file to cache, use:
  header("Cache-Control: max-age=2592000"); //30days (60sec * 60min * 24hours * 30days)

?>

note: I cheated and found this somewhere else…

@DaveMaxwell,

Thank you,I will give a try…by the way can I ask you,do you also have this when you are writing web application?

Thank you.

Honestly, I don’t use AJAX all that much - I haven’t found a use case where it added that much value to my clients. A few pieces here and there, but I’m more old school and try to get as much as I can before I send anything to the client. And I’m not a huge fan of caching anything unless I’m 100% sure it’s not going to change for an extended period of time.

But that’s just me. Everyone’s different.

@DaveMaxwell,

Thank you for the reply.