-
Notifications
You must be signed in to change notification settings - Fork 357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: index html caching #18458
fix: index html caching #18458
Conversation
dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/filter/HttpNoCacheFilter.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Austin McGee <[email protected]>
Quality Gate passedIssues Measures |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! Few minor comments as discussed.
@netroms could you take a quick look at this to make sure we're doing the filtering in the right place? Thanks!
dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/servlet/DhisWebApiWebAppInitializer.java
Outdated
Show resolved
Hide resolved
dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/filter/HttpNoCacheFilter.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Austin McGee <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change looks good to me! Tested here https://dev.im.dhis2.org/pr-18458
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No can't do it like this. I know of HTML we do want to cache. So the headers need to be added to the specific endpoints, not always for all HTML responses.
@jbee which HTML are you thinking of? We discussed making the regex more targeted, we can do that if there are html files elsewhere that should be cached. It is generally always problematic to cache application root html files, and this was the previous behavior. @netroms and I also discussed that we need to address static asset caching headers more holistically so this will be updated before 42. |
@amcgee I was thinking about the |
Thanks @jbee! Regarding the Maps app, I tried switching the order of operations in the filter as recommended: chain.doFilter(request, response);
if (m.find() && HttpMethod.GET.matches(request.getMethod())) {
ContextUtils.setNoStore(response);
} But still the headers don't seem to get applied to the Maps app 🤔 any other ideas? @amcgee (This screenshot is from before changing the order, but it still looks the same after -- included for illustration) |
@KaiVandivier in that case I would revert the change of order again. Send me a message on slack so we can talk about the request this does and I maybe can help debugging it. |
Quality Gate passedIssues Measures |
This should fix these two issues, which both seem to be caused by HTML files being cached and served by the browser:
It seems that in v42, responses for HTML files are missing the
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
headers that previous versions added to responses -- these changes reintroduce themTo do
index.html
andplugin.html
for routes like/dhis-web-
and/api/apps/
, for example. Consider other HTML files, like custom reports or custom data entry formsTesting
The change can be tested by opening up apps and checking the response headers on HTML files -- they should include the
Cache-Control
headers above. Other requests should not all have the same headers -- a few do, like/api/me/dashboard
andapi/system/info
, but not all. NB: If opening up apps at a URL that hosted a previous v42 instance, you made need to get past previously cached versions ofindex.html
, which can be done by reloading multiple times, hard reloading, or using theDisable Cache
option in the Network panel of dev toolsHere are some examples of response headers after the changes:
![Screenshot 2024-08-27 at 2 15 35 PM](https://github.com/user-attachments/assets/3dd951bf-9564-4701-b4bf-b7e933a1133
6)