Skip to content

Make .htaccess cache JS and CSS by default #11496

Closed

Description

@henryk

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

  1. Do a standard installation of owncloud 7.0.2 on Ubuntu 14.04 with Apache using the opensuse repositories.
  2. In Firefox, open the Network web developer tool (Shift-Ctrl-Q) and look at the requests and summaries.
  3. Load the default "Files" app after login once (https://…/owncloud/index.php/apps/files/).
  4. 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

  1. LukasReschke commented on Oct 9, 2014

    @LukasReschke
    Contributor

    @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! :-)

  2. LukasReschke commented on Oct 9, 2014

    @LukasReschke
    Contributor

    @carlaschroder For documentation parts.

  3. LukasReschke commented on Oct 9, 2014

    @LukasReschke
    Contributor

    This is an enhancement request preferably to be done after #11374 is closed.

    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)

  4. carlaschroder commented on Oct 9, 2014

    @carlaschroder

    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>

  5. added a commit that references this issue on Oct 14, 2014
    4b5c7d3
  6. added a commit that references this issue on Oct 14, 2014
    766314a
  7. MorrisJobke commented on Oct 14, 2014

    @MorrisJobke
    Contributor

    @carlaschroder The .htaccess is already deployed via package and it doesn't require any additional steps.

  8. HannesSommer commented on Dec 27, 2014

    @HannesSommer

    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)$".

  9. MorrisJobke commented on Jan 5, 2015

    @MorrisJobke
    Contributor

    @HannesSommer Your issue will be fixed in ownCloud 8.0.0

  10. HannesSommer commented on Jan 5, 2015

    @HannesSommer

    Great! That was super fast :)

  11. locked as resolved and limited conversation to collaborators on Aug 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions