Try to cache a JSON Document
Cache
and Expire
Headers are set correctly.
Expire
header is set to the past.
Cache
headers are set to not cache
Latest Joomla 3.8.3
I stumbled upon this while developing a module. I was using com_ajax for communication, when I couldn't get the headers right, trying to take advantage of client-side caching.
I set the $app->allowCache(true), which should do the job, one would think, but this wasn't working.
I found out that the render() function in JsonDocument has a hardcoded:
$app->allowCache(false);
at https://github.com/joomla/joomla-cms/blob/staging/libraries/src/Document/JsonDocument.php#L71
If I remove that line, it works fine, though I don't know if any extensions would have problems, if browser cache on the site would be enabled.
This line should not be there at all, or handled differently in order to not break b/c.
it is also an issue, as the given parameter is not honored.
I believe this should be fixed, as caching JSON responses on the client is legit and Joomla should not get in the way of that.
For now, in my module I did an ugly workaround by just returning the headers and data and exiting prematurely. However, I would prefer to not skip the remaining Joomla stuff that would be happening, like some event triggers being handled by some plugins.
I am happy to provide a PR for this.
Labels |
Added:
?
|
Category | ⇒ | Libraries |
Labels |
Added:
J3 Issue
|
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2018-03-25 18:03:21 |
Closed_By | ⇒ | brianteeman |
Closing this here as there is another discussion on #19941