Coder Social home page Coder Social logo

Handle cache in .htaccess about ecoindex HOT 8 CLOSED

yaaax avatar yaaax commented on August 14, 2024 1
Handle cache in .htaccess

from ecoindex.

Comments (8)

JulienWilhelm avatar JulienWilhelm commented on August 14, 2024 1

Some complements ?
Gzip seems already activated, but, who knows.

<IfModule mod_deflate.c>
	# Enables Gzip compression.
	SetOutputFilter DEFLATE
	AddOutputFilterByType DEFLATE text/html text/css application/x-javascript
</IfModule>

# Prevents browsing directories.
Options -Indexes

from ecoindex.

JulienWilhelm avatar JulienWilhelm commented on August 14, 2024 1

Done. Efficient client-side caching and network compression.

from ecoindex.

yaaax avatar yaaax commented on August 14, 2024

Voici le .htaccess au complet :

AuthUserFile /home/ecoindex.neutral.hosting/public_html/.htpasswd
AuthType Basic
AuthName "Accès réservé"
Require valid-user

RewriteEngine On

# redirect result without params to to 404
RewriteCond %{REQUEST_URI} ^/resultat/index\.html$
RewriteCond %{QUERY_STRING} !(^|&)id($|&)
RewriteRule ^(.*)$ /404.html? [L,R=301]

# prevent bandwith theft from assets
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?:\/\/(.+\.)?ecoindex\.(fr|neutral\.hosting) [NC]
RewriteRule .*\.(jp(e)?g|gif|bmp|png|svg|mp4|webm)$ https://imgur.com/ZtXiCBw.gif [L,R]

# enforce https
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# remove www
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

# Don't allow anyone to see my .htaccess file
<Files .htaccess>
  Order allow,deny
  Deny from all
</Files>

<IfModule mod_expires.c>
    # Sets or disables the cache.
    ExpiresActive On
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType image/svg+xml "access plus 1 year"
    ExpiresByType text/css "access plus 1 year"
    ExpiresByType application/javascript "access plus 1 year"
</IfModule>
<IfModule mod_headers.c>
    # Sets or disables the cache.
    <filesMatch "\.(jpe?g|png|svg|css|js)$">
        Header set Cache-Control "max-age=31536000, public"
    </filesMatch>
</IfModule>

<IfModule mod_deflate.c>
	# Enables Gzip compression.
	SetOutputFilter DEFLATE
	AddOutputFilterByType DEFLATE text/html text/css application/x-javascript image/svg+xml
</IfModule>

# Prevents browsing directories.
Options -Indexes

ErrorDocument 404 /404/

from ecoindex.

JulienWilhelm avatar JulienWilhelm commented on August 14, 2024

(we could add gzip on svg if we plan to load svg as external resources)

from ecoindex.

yaaax avatar yaaax commented on August 14, 2024

Updated on prod.

Comment updated: #103 (comment)

from ecoindex.

yaaax avatar yaaax commented on August 14, 2024

(we could add gzip on svg if we plan to load svg as external resources)

We do that for the logos right? (or externally means "from another server"?)

from ecoindex.

JulienWilhelm avatar JulienWilhelm commented on August 14, 2024

Gzip compression will only apply to resources loaded by the network (like <img src="logo.svg" />, for a svg).

We could add it, just in case (the same logic apply to caching).

from ecoindex.

yaaax avatar yaaax commented on August 14, 2024

Yes 👍

  • EcoIndex logo : <img src="/images/logo.svg" width="132" height="36" alt="ecoIndex, retour à la page d’accueil">
  • Green IT logo : <img src="/images/logo-greenit.png" width="126" height="50" alt="Association Green IT (prononcer grine • aïe • ti)">

I've updated the .htaccess on the server + updated the comment ☝️
(added: image/svg+xml)

from ecoindex.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.