-1

I was wondering how can cache a XHR locally on my computer and use it for next time. Well I visit a online shop regular in the order page there is a form which includes a field with XHR and I have to fill then and then complete my order with submit button. Some times as there is heavy traffic on this site this files fail to load on my system and I have to refresh the page many times to get it. Is there any way to cache this to my computer and use it for next time. I have to say other fields of the form load completely and have not problem with them.

4
  • Is there any way to cache this to my computer and use it for next time - no
    – Bravo
    Commented Nov 6, 2019 at 10:31
  • Why this is no possible? The XHR just load a cites with ID which does not change for ever and goggle chrome never store it in cache to use next time.
    – MSSHD
    Commented Nov 6, 2019 at 10:41
  • goggle chrome never store it in cache - chrome has this habit of not caching what you expect would be cached, and caching what you expect would not be cached - honestly, why it's so popular is a bewilderment
    – Bravo
    Commented Nov 6, 2019 at 10:43
  • So how I can call this as fast as I want?
    – MSSHD
    Commented Nov 6, 2019 at 10:46

2 Answers 2

3

XHR responses are cached automatically in the browser cache if your HTTP cache headers permit it. For the simplest case, try sending your response with "Cache-Control: public, max-age=0" and "Last-Modified: [your timestamp]" headers to see the browser generating conditional requests with "If-Modified-Since" request headers, where you can then send just a "304 Not Modified" response and have the XHR API expose your cached response as a "200 Ok" response to your script. Or you can experiment with max-age/s-maxage and "Expires:" headers such that your request is served directly from the browser cache without even revalidation/server-roundtrip. You can also use "ETag" headers instead of "Last-Modified", but since ETags can be used for fingerprinting, I expect these to become inacceptable in the future for public HTTP access.

Note if you're using HTTP/2 with server-pushed resources, the rules change somewhat and cached responses are scoped to a session, also to avoid fingerprinting.

1
  • I added Cache-Control and Last-Modified headers and the browser is not sending "if-modified-since". Commented Dec 12, 2020 at 16:16
1

You can use Local Storage to store any data. https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage Use local overrides to create your own local js for remote site and use localStorage. https://developers.google.com/web/updates/2018/01/devtools#overrides

6
  • How can store any data? for this could you please explain?
    – MSSHD
    Commented Nov 6, 2019 at 10:39
  • even if you could store the result of the XHR, it wouldn't help, since the website code won't look for the data where you've decided to store it
    – Bravo
    Commented Nov 6, 2019 at 10:44
  • 1
    With local overrides you can change javascript of any site, you can just add code that will be store data to localstorage after XHR. Commented Nov 6, 2019 at 10:48
  • This is the site I am taking about esale.ikco.ir/#!/loginFromWizard the field I got problem in number six.
    – MSSHD
    Commented Nov 6, 2019 at 10:50
  • Then you can substitute stored data instead of data received from XHR Commented Nov 6, 2019 at 10:51

Not the answer you're looking for? Browse other questions tagged or ask your own question.