Je website snelheid verbeteren met cache headers

Naast snelle hosting kun je je website optimaliseren om de laadtijd van je website te verkorten. Dit doe je onder andere met cache headers.

 

Met cache headers in je .htaccess bestand kun je ervoor zorgen dat sommige website bestanden bij de bezoeker in het cache geheugen opgeslagen worden.
Hierdoor hoeven niet alle bestanden iedere keer opnieuw gedownload te worden en laad je website dus sneller.
Volg de onderstaande stappen om je .htaccess bestand van caching headers te voorzien.

 

Open het .htaccess bestand dat in de root (hoofdmap) van je website staat.
Dit kun je doen met een FTP client zoals Filezilla of met bestandsbeheer in DirectAdmin.
Heb je nog geen .htaccess bestand in de root van je website staan, maak dan een nieuw tekst bestand aan en geef deze de naam .htaccess

 

Nadat je dit gedaan hebt kopieer je de onderstaande cache headers code en plak je deze in het .htaccess bestand.

# START GZIP COMPRESSION

<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>

# END GZIP COMPRESSION
# START DEFLATE COMPRESSION

AddOutputFilterByType DEFLATE "application/atom+xml" \
"application/javascript" \
"application/json" \
"application/ld+json" \
"application/manifest+json" \
"application/rdf+xml" \
"application/rss+xml" \
"application/schema+json" \
"application/vnd.geo+json" \
"application/vnd.ms-fontobject" \
"application/x-font" \
"application/x-font-opentype" \
"application/x-font-otf" \
"application/x-font-truetype" \
"application/x-font-ttf" \
"application/x-javascript" \
"application/x-web-app-manifest+json" \
"application/xhtml+xml" \
"application/xml" \
"font/eot" \
"font/otf" \
"font/ttf" \
"font/opentype" \
"image/bmp" \
"image/svg+xml" \
"image/vnd.microsoft.icon" \
"image/x-icon" \
"text/cache-manifest" \
"text/css" \
"text/html" \
"text/javascript" \
"text/plain" \
"text/vcard" \
"text/vnd.rim.location.xloc" \
"text/vtt" \
"text/x-component" \
"text/x-cross-domain-policy" \
"text/xml"
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml

# END DEFLATE COMPRESSION
# START ENABLE KEEP ALIVE

Header set Connection keep-alive

# END ENABLE KEEP ALIVE
# START EXPIRES CACHING #

ExpiresActive On
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/x-icon "access 1 year"
ExpiresByType image/svg+xml "access plus 1 month"
ExpiresByType audio/ogg "access plus 1 year"
ExpiresByType video/mp4 "access plus 1 year"
ExpiresByType video/ogg "access plus 1 year"
ExpiresByType video/webm "access plus 1 year"
ExpiresByType application/atom+xml "access plus 1 hour"
ExpiresByType application/rss+xml "access plus 1 hour"
ExpiresByType application/pdf "access 1 month"
ExpiresByType application/javascript "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType text/x-component "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType font/opentype "access plus 1 month"
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
ExpiresByType application/x-font-ttf "access plus 1 month"
ExpiresByType application/font-woff "access plus 1 month"
ExpiresByType application/font-woff2 "access plus 1 month"
ExpiresDefault "access 1 month"

# END EXPIRES CACHING #
# BEGIN Cache-Control Headers

Header set Cache-Control "public"
Header set Cache-Control "public"
Header set Cache-Control "private"
Header set Cache-Control "private, must-revalidate"

# END Cache-Control Headers

Sla nu het bestand op en zet deze in de root van je website.

Je hebt succesvol je website snelheid geoptimaliseerd.
De pagina's zullen nu sneller laden dan voorheen.

  • 19 gebruikers vonden dit artikel nuttig
Was dit antwoord nuttig?

Gerelateerde artikelen

Gratis Online Favicon Generator

Wanneer we het over handige tools hebben dan mag een gratis online favicon generator niet...

Hoe kan ik een MySQL Database aanmaken?

Tegenwoordig maken de meeste websites zoals Joomla, Drupal, Magento en Wordpress gebruik van een...

Hoe maak ik verbinding met SSH of SFTP?

Wil je via SSH verbinden met de server of gebruik maken van SFTP?Deze SSH handleiding legt uit...

Hoe upload ik mijn website naar de webserver?

Wanneer je een webhosting pakket en domeinnaam hebt aangeschaft dan wil je daar natuurlijk je...

Van HTTP naar HTTPS redirecten: Hoe doe je dat?

Nadat je een (gratis) SSL Certificaat hebt aangeschaft zodat je HTTPS voor je domeinnaam krijgt...