Content-Type Text/HTML is not cached

432
November 22, 2016, at 11:51 AM

I have a simple situation. I am using jQuery's ajax method to get some data.

When I refer to "api.json" in url, I get proper response headers with etag, cache-control etc etc. The content-type is also "application/json"

But when I refer to a "api.php" in url, the response header changes, this time there is no etag, no cache-control and content-type is also "text/html" ( which is understood ).

In that php file the returned data is properly formatted using json_encode().

What I do not understand is, why etag and other caching headers are misbehaving?

How can I enable them to cache properly?

Answer 1

The ETag header present in cross-origin responses will not be accessible to client-side code unless the server includes an Access-Control-Expose-Headers header in its response, with a value of "ETag". This is true of any "non-simple" response headers.

From CORS

7.1.1 Handling a Response to a Cross-Origin Request User agents must filter out all response headers other than those that are a simple response header or of which the field name is an ASCII case-insensitive match for one of the values of the Access-Control-Expose-Headers headers (if any), before exposing response headers to APIs defined in CORS API specifications.

Simple response headers are limited to:

  1. Cache-Control
  2. Content-Language
  3. Content-Type
  4. Expires
  5. Last-Modified
  6. Pragma

All other headers that the client needs to access in the response must be "exposed" via the response header I mentioned above.

Rent Charter Buses Company
READ ALSO
Expanding child UL when clicked not working in jQuery

Expanding child UL when clicked not working in jQuery

im new to JS and having an issue toggle show / hide for a hidden ul menu.

279
Javascript getting params from the url [duplicate]

Javascript getting params from the url [duplicate]

This question already has an answer here:.

455
How to modify a dynamically created content using jQuery

How to modify a dynamically created content using jQuery

Firstly a bit of background: I'm modifying Drupal's backend (Node creation form) to dynamically add an html to a dynamically created element. .

285
Laravel Ajax Success Message: Returning Contact Form Name Input

Laravel Ajax Success Message: Returning Contact Form Name Input

Thanks guys for looking into my question. I have this form that I use ajax to submit to the mysql database using laravel.

410