Voeg Expires-headers toe

Bij het testen van de site met Yahoo YSLOW staat bovenstaand bericht. Dus ik weet niet hoe ik verlopen headers moet toevoegen. Alle hulp wordt op prijs gesteld?


Antwoord 1, autoriteit 100%

De gemakkelijkste manier om deze headers toe te voegen is een .htaccess-bestand dat enige configuratie aan uw server toevoegt. Als de activa worden gehost op een server die u niet beheert, kunt u er niets aan doen.

Houd er rekening mee dat je bij sommige hostingproviders geen .htaccess-bestanden mag gebruiken, dus controleer hun voorwaarden als het niet lijkt te werken.

Het HTML5Boilerplate-project heeft een uitstekend .htaccess-bestand dat de nodige instellingen dekt. Bekijk het relevante deel van het bestand in hun Github-repository

Dit zijn de belangrijke dingen

# ----------------------------------------------------------------------
# Expires headers (for better cache control)
# ----------------------------------------------------------------------
# These are pretty far-future expires headers.
# They assume you control versioning with filename-based cache busting
# Additionally, consider that outdated proxies may miscache
# www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/
# If you don't use filenames to version, lower the CSS and JS to something like
# "access plus 1 week".
<IfModule mod_expires.c>
  ExpiresActive on
# Your document html
  ExpiresByType text/html "access plus 0 seconds"
# Media: images, video, audio
  ExpiresByType audio/ogg "access plus 1 month"
  ExpiresByType image/gif "access plus 1 month"
  ExpiresByType image/jpeg "access plus 1 month"
  ExpiresByType image/png "access plus 1 month"
  ExpiresByType video/mp4 "access plus 1 month"
  ExpiresByType video/ogg "access plus 1 month"
  ExpiresByType video/webm "access plus 1 month"
# CSS and JavaScript
  ExpiresByType application/javascript "access plus 1 year"
  ExpiresByType text/css "access plus 1 year"
</IfModule>

Ze hebben gedocumenteerd wat dat bestand doet, het belangrijkste is dat u uw CSS- en Javascript-bestanden moet hernoemen wanneer ze veranderen, omdat de browsers van uw bezoekers ze een jaar lang niet meer zullen controleren, nadat ze in de cache zijn geplaatst.


Antwoord 2, autoriteit 16%

probeer deze oplossing en het werkt prima voor mij

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType text/css "access plus 1 year"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
<IfModule mod_headers.c>
  <FilesMatch "\.(js|css|xml|gz)$">
    Header append Vary: Accept-Encoding
  </FilesMatch>
</IfModule>
<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>
<IfModule mod_deflate.c>
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/css text/plain text/xml text/x-js text/js 
</IfModule>
## EXPIRES CACHING ##

Antwoord 3, autoriteit 4%

Je kunt ze toevoegen aan je htaccess-bestand of vhost-configuratie.

Zie hier: http://httpd.apache.org/docs/2.2 /mod/mod_expires.html

Maar tenzij u de eigenaar bent van die domeinen… hebben wij uw controle.


Antwoord 4

<IfModule mod_expires.c>
    # Enable expirations
    ExpiresActive On 
    # Default directive
    ExpiresDefault "access plus 1 month"
    # My favicon
    ExpiresByType image/x-icon "access plus 1 year"
    # Images
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    # CSS
    ExpiresByType text/css "access plus 1 month"
    # Javascript
    ExpiresByType application/javascript "access plus 1 year"
</IfModule>

Antwoord 5

In ASP.NET is er een soortgelijk object, u kunt caching-gedeelten in WebFormsUserControls gebruiken om objecten van een pagina voor een bepaalde periode in de cache op te slaan en serverbronnen te sparen. Dit wordt ook wel fragmentcaching genoemd.
Als u deze code bovenaan uw gebruikersbesturingselement plaatst, wordt een versie van het besturingselement 150 seconden in de uitvoercache opgeslagen.
U kunt uw eigen besturingselement maken dat een verlopen-header zou bevatten voor een specifieke bron die u wilt.

<%@ OutputCache Duration="150" VaryByParam="None" %>

Dit artikel legt het volledig uit:
Cachegedeelten van een ASP.NET-pagina

Other episodes