Skip to content
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

Merged
merged 22 commits into from
Nov 6, 2024
Merged

fix: index html caching #18458

merged 22 commits into from
Nov 6, 2024

Conversation

KaiVandivier
Copy link
Contributor

@KaiVandivier KaiVandivier commented Aug 27, 2024

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 them

To do

  • Consider HTML files to handle -- currently handling all HTML files; could instead handle only index.html and plugin.html for routes like /dhis-web- and /api/apps/, for example. Consider other HTML files, like custom reports or custom data entry forms
  • Think about what the implications might be of doing this for non-app html files (or html files that aren't index or plugin).
  • Need to think about where this should be placed... are bundled apps served with this servlet?
  • Why did this stop working in v42? Possibly due to restructuring to support embedded tomcat and/or removal of struts for bundled app serving
  • Rename this filter; maybe reuse the app override filter

Testing

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 and api/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 of index.html, which can be done by reloading multiple times, hard reloading, or using the Disable Cache option in the Network panel of dev tools

Here are some examples of response headers after the changes:
Screenshot 2024-08-27 at 2 16 10 PM
Screenshot 2024-08-27 at 2 15 54 PM
![Screenshot 2024-08-27 at 2 15 35 PM](https://github.com/user-attachments/assets/3dd951bf-9564-4701-b4bf-b7e933a1133
Screenshot 2024-08-27 at 2 24 24 PM
Screenshot 2024-08-27 at 2 23 35 PM
Screenshot 2024-08-27 at 2 23 28 PM
6)

Copy link

@amcgee amcgee requested a review from a team August 27, 2024 15:49
Copy link
Member

@amcgee amcgee left a 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!

@amcgee amcgee added the deploy Deploy DHIS2 instance with IM. label Oct 8, 2024
Copy link
Member

@amcgee amcgee left a 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

@amcgee amcgee requested review from mortenoh, netroms and jbee October 8, 2024 09:30
Copy link
Contributor

@jbee jbee left a 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.

@amcgee
Copy link
Member

amcgee commented Oct 9, 2024

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.

@jbee
Copy link
Contributor

jbee commented Oct 10, 2024

@amcgee I was thinking about the /openapi/openapi.html and others in the /openapi path. But you are also allowed to use /api/dataElements/openapi.html and so forth.

@KaiVandivier
Copy link
Contributor Author

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)
new-regex-maps-not-working

@jbee
Copy link
Contributor

jbee commented Oct 21, 2024

@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.

@amcgee amcgee added deploy Deploy DHIS2 instance with IM. and removed deploy Deploy DHIS2 instance with IM. labels Oct 30, 2024
@KaiVandivier KaiVandivier added deploy Deploy DHIS2 instance with IM. and removed deploy Deploy DHIS2 instance with IM. labels Nov 4, 2024
@KaiVandivier
Copy link
Contributor Author

The Maps HTML seems to be working fine on the IM deployment; maybe there was something weird on my local instance 🤔

So I think this is nearly done; just discussing one last thing with Austin

Screenshot 2024-11-04 at 18 23 04

Copy link

sonarqubecloud bot commented Nov 5, 2024

@amcgee amcgee merged commit e9cb6ac into master Nov 6, 2024
15 checks passed
@amcgee amcgee deleted the fix-index-html-caching branch November 6, 2024 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deploy Deploy DHIS2 instance with IM.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants