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

Optimize client side resource caching #10213

Closed
tsteur opened this issue Jun 6, 2016 · 2 comments
Closed

Optimize client side resource caching #10213

tsteur opened this issue Jun 6, 2016 · 2 comments
Labels
c: Performance For when we could improve the performance / speed of Matomo.

Comments

@tsteur
Copy link
Member

tsteur commented Jun 6, 2016

I've recently seen a couple of Piwik installations that were not configured well in terms of caching static resources and Piwik ended up being much slower therefore. Like 400ms spent server side to load the initial page but then 2 or 3 more seconds just to load the resources even on repeat visit. So far it's basically been up to the user to configure a server correctly for static caching and there are projects like https://github.com/perusio/piwik-nginx that do this already I think (haven't actually checked whether caching is enabled there).

See for example
image
image
image

It would be nice to find a couple of ways to make this easier for users and I would differentiate three things here:

  • Our minified / merged JS and CSS resources like Proxy.getJs and Proxy.getCss that have a cache buster parameter ?cb=34242432434 . This cache buster changes whenever something in Piwik changes so we can cache these resources pretty much for a long time. These files are actually served with Piwik via PHP and maybe we could remove the must-revalidate and send a max-age here so it doesn't even go to the sever again to avoid the 304. In the 304 we detect whether content changed this is slow. Optimizing this should already help a lot as they are quite big files and fetching them is slow.
  • Static resources like *.js, *.css, *.html that have a cache buster parameter ?cb=34242432434 as well but they are not served via PHP. This cache buster changes whenever something in Piwik changes so we can cache these resources pretty much for a long time.
  • Other static resources like images, fonts, ... with no cache buster. They have no cache buster parameter and can be maybe cached for a shorter time, etags can be used if server supports it, must-revalidate can be used etc.

One step would be to collect these kinda information, to write about it in the FAQ and to create smaller issues for individual tasks. Maybe we could later even have a system check that kind of checks whether resources are served from cache (we could maybe detect it eg via performance API and/or via service workers).

For installations that use HTTPS we could possibly add service workers see eg https://developers.google.com/web/fundamentals/getting-started/your-first-progressive-web-app/step-04?hl=en and https://jakearchibald.com/2014/offline-cookbook/ and cache the resources client side this way (eg if the server doesn't send proper cache headers or always). This would be independent of the server and make it easier to use and install Piwik. Because of the cache buster we should be able to correctly validate and invalidate all kind of resources. In development mode we could either disable the service workers or developers simply disable caching in development tools while developing. Also it doesn't work with self signed certificates, at least in chrome. It shouldn't be too much work to create the workers. In a more extended version we could detect whether a user is on a slow network or in power saving mode and in such a case serve more resources from service workers.

Any other thoughts?

@mattab mattab added the c: Performance For when we could improve the performance / speed of Matomo. label Jul 7, 2016
@mattab
Copy link
Member

mattab commented Jul 7, 2016

For installations that use HTTPS we could possibly add service workers see eg https://developers.google.com/web/fundamentals/getting-started/your-first-progressive-web-app/step-04?hl=en and https://jakearchibald.com/2014/offline-cookbook/

interesting!

This would be independent of the server and make it easier to use and install Piwik.

Caching assets in client will make Piwik faster to use and to load, but would it also make it easier to install Piwik?

For installations that use HTTPS

I was curious exactly why service works work only on HTTPS and here it is:

Service worker functionality is only available on pages that are accessed via HTTPS (https://localhost and equivalents will also work, to facilitate testing). To learn about the rationale behind this restriction check out Prefer Secure Origins For Powerful New Features from the Chromium team.

Any other thoughts?

Service workers look awesome!

@mattab mattab added this to the 3.0.0 milestone Jul 14, 2016
@tsteur
Copy link
Member Author

tsteur commented Jan 3, 2024

Closing this as it looks like things are working well and for static resources like images we can't do much about it.

@tsteur tsteur closed this as not planned Won't fix, can't repro, duplicate, stale Jan 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: Performance For when we could improve the performance / speed of Matomo.
Projects
None yet
Development

No branches or pull requests

2 participants