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

Add htaccess rules to cache static content for webpage loading performance #575

Open
danreb opened this issue Dec 31, 2015 · 3 comments
Open

Comments

@danreb
Copy link

danreb commented Dec 31, 2015

Hi There,

We've just launch our first Grav website, upon checking the website through webpagetest.org to test loading performance it gives us a big RED F for caching. Coming from Drupal CMS background there's a htaccess rules that Drupal is using to work around with this. I copy pasted the htaccess rules and it fixes the problem. I am suggesting it to be added and be shipped with Grav htaccess files, following are the rules i've added

# Requires mod_expires to be enabled.
<IfModule mod_expires.c>
  # Enable expirations.
  ExpiresActive On

  # Cache all files for 2 weeks after access (A).
  ExpiresDefault A1209600

  <FilesMatch \.php$>
    # Do not allow PHP scripts to be cached unless they explicitly send cache
    # headers themselves. Otherwise all scripts would have to overwrite the
    # headers set by mod_expires if they want another caching behavior. This may
    # fail if an error occurs early in the bootstrap process, and it may cause
    # problems if a non-Drupal PHP file is installed in a subdirectory.
    ExpiresActive Off
  </FilesMatch>
</IfModule>

Regards,
Danreb

@flaviocopes
Copy link
Contributor

Tested and works, while I'm not sure it's a good default for every site, as cache is something you enable only when deploying a site, not when developing for example, while our .htaccess contains just what's needed to run. And not everyone would need that maybe. Just tested that getgrav.org gets all A/B on that webpagetest.org test, but uses a CDN for assets so that line you propose is not needed to get an optimal performance for assets caching.

@rhukster can we add this commented in the htaccess, ready to be used, or should we add a "improving performance" section in the Learn docs with this and other suggestions?

@rhukster
Copy link
Member

Yes this is something for the performance and optimization section of the documentation. Not something for the stock .htaccess file.

Will leave open to remind me to add.

@benblee
Copy link
Contributor

benblee commented Jan 9, 2016

Is this better set in a way that adds allowed filetypes instead of any file except .php?

I'm using this for fonts on http://www.smartgravity.com and image types could easily be added by the user.

<filesMatch "\.(eot|svg|ttf|woff|woff2)$">
    Header set Cache-Control "max-age=604800, public"
</filesMatch>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants