flarum / framework

Simple forum software for building great communities.
http://flarum.org/
6.29k stars 835 forks source link

Add gzip/caching directives to .htaccess and nginx configuration #514

Closed tobyzerner closed 8 years ago

tobyzerner commented 9 years ago

_1 Upvote_ Something like:

<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/plain text/css text/xml text/html text/javascript application/javascript application/x-javascript application/xml application/json application/vnd.api+json
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>

<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault "access plus 1 seconds"
  ExpiresByType image/gif "access plus 2678400 seconds"
  ExpiresByType image/jpeg "access plus 2678400 seconds"
  ExpiresByType image/png "access plus 2678400 seconds"
  ExpiresByType text/css "access plus 2678400 seconds"
  ExpiresByType text/javascript "access plus 2678400 seconds"
  ExpiresByType application/x-javascript "access plus 2678400 seconds"
</IfModule>

<IfModule mod_headers.c>
  <FilesMatch "\.(ico|flv|jpg|jpeg|png|gif|css|swf|js)$">
    Header set Cache-Control "max-age=2678400, public"
  </FilesMatch>
</IfModule>

Thought it would be worth opening this up for discussion before adding though, because I don't know much about Apache config!

franzliedke commented 9 years ago

:+1:

I can take a look at this as part of flarum/issue-archive#390.

Mecvak commented 9 years ago

Having devs help write the config means it's going to be pretty optimal since you know the backend and know what opportunities (like caching) you can give the webserver.

However, the installation guide should be basic installation. You really don't want to be debugging through various modules when you don't even know if the basic set up is correct. Plus, by suggesting modifying modules, you're now modifying other sites they may be running and opens up the risk of "I installed flarum and now buggy php program X stopped working! Flarum broke it!" etc etc. Wasn't aware you could add them in htaccess.

Instead, maybe start a "Optimize Flarum" or some such page where users have a running flarum install that works and want it to use less resources or to make it faster. For example, I dropped page responses from ~240ms to ~180ms by utilizing php5-fpm's op-cache which is pretty sweet. But I wouldn't suggest it for someone who's definition of "configuring" is copying and pasting the install guide config.

My 2c

franzliedke commented 8 years ago

Currently working on adapting the rules from here. :)

franzliedke commented 8 years ago

Can someone review this on Apache? Nginx works fine for me...

phodal commented 8 years ago

@franzliedke Today I do some config with Nginx, it seems the API don't have compress. And I compare the config between Nginx and Apache, I found in Nginx config lost one gzip_types which is application/vnd.api+json.

franzliedke commented 7 years ago

@phodal I don't see application/vnd.api+json in our Apache config.

I jut added one line that was forgotten in the Nginx config, though, thanks for the heads-up.