Repository navigation
Description
This is an enhancement request preferably to be done after #11374 is closed.
The default owncloud installation does not instruct browsers to cache JS and CSS files, even though there are quite a lot of them. This leads to many unnecessary HTTP requests when loading the web interface, delaying the page load by a significant amount of time.
Steps to reproduce
- Do a standard installation of owncloud 7.0.2 on Ubuntu 14.04 with Apache using the opensuse repositories.
- In Firefox, open the Network web developer tool (Shift-Ctrl-Q) and look at the requests and summaries.
- Load the default "Files" app after login once (https://…/owncloud/index.php/apps/files/).
- Load it again.
Actual results
Both steps 3 and 4 issue over 100 HTTP requests. For my installation step 4 takes ~21 seconds to fully complete. Most requests in step 4 are answered with an HTTP 304 Not Modified. No cache-control header is sent in step 3. Note that the .css and .js URLs already have a cache buster appended to them, even if it's not perfect yet (see #11374).
Expected results
A cache-control header should have been sent in step 3. None of the static .css and .js files should have been requested in step 4.
Proposed fix
The default .htaccess file should have something like this in it:
<IfModule mod_headers.c>
<FilesMatch ".(css|js)$">
Header set Cache-Control "max-age=7200, public"
</FilesMatch>
</IfModule>also, the installation instructions should call for the administrator to enable the headers Apache module (sudo a2enmod headers). Due to the existing cache buster this change should be almost safe, except for app upgrades (which will break for at most 2 hours). When #11374 is finally fixed, the max-age value can be increased almost without bounds (I'm using 2592000 on my site).
Note that the http://demo.owncloud.org/ installation already does include Cache-Control headers (which is where I got the 7200 from).
With this caching enabled, loading of the "Files" app drops from ~140 HTTP requests to ~16 HTTP requests for me, reducing load time from ~21 seconds to ~6 seconds.
Activity
LukasReschke commentedon Oct 9, 2014
@henryk You are more then welcome to submit a pull request, just do the change in this file. Would you mind to do that? - Thanks a lot! :-)
LukasReschke commentedon Oct 9, 2014
@carlaschroder For documentation parts.
LukasReschke commentedon Oct 9, 2014
This will most likely not be done in time for ownCloud 7 but for master you can already submit a change. If you like I can also guide you how to do the changes pointed out in #11374 - just ping me in IRC (AnybodyElse)
carlaschroder commentedon Oct 9, 2014
If this is not going to be in oc7, then what should the docs say? Do you want instructions for admins to manually configure htaccess? like:
"Enhance performance by caching .css and .js files. Do this by adding this section to your .htaccess file (typically, this is in /var/www/owncloud/.htaccess)::
< IfModule mod_headers.c>
< FilesMatch ".(css|js)$">
Header set Cache-Control "max-age=7200, public"
< /FilesMatch>
< /IfModule>
adding cache control headers for css and js - fixes #11496
Merge pull request #11556 from owncloud/cache-js-and-css
MorrisJobke commentedon Oct 14, 2014
@carlaschroder The .htaccess is already deployed via package and it doesn't require any additional steps.
HannesSommer commentedon Dec 27, 2014
Great patch! Just a small hint: the regular expression of the FilesMatch is probably not as intended because the
.is not escaped. As intended would probably be"\.(css|js)$".MorrisJobke commentedon Jan 5, 2015
@HannesSommer Your issue will be fixed in ownCloud 8.0.0
HannesSommer commentedon Jan 5, 2015
Great! That was super fast :)