Hinzufügen Expire Header in PHP kann nicht damit es funktioniert
-
25-09-2019 - |
Frage
Ich habe YSlow Add-on installiert
Wenn ich meine Anwendung in YSlow I get prüft Add Verfällt Header , das weiß ich nicht
ich für relevante Fragen in SO gesucht und auch gefunden Google ich diese Methode angemessen
<?
header("Expires:".gmdate('D, d M Y H:i:s \G\M\T', time() + 3600));
header("Cache-Control: no-cache");
header("Pragma: no-cache");
ob_start();
session_cache_limiter('public');
session_start();
?>
<html>
Aber noch zeigt es mir gleiche
Wie ich Neuling bin, weiß ich nicht viel über .htaccess
Bitte helfen Sie verbessern mir Anwendungen Leistung
Vielen Dank im Voraus
Wazzy
Lösung
Das setzt sie nur für Ihre Seite Inhalt und nicht Dinge wie Bilder und CSS-Dateien, ich auf dem Screenshot bemerkte es sagt 42 Dateien, die vermutlich das sind Ihre Bilder, CSS, JS, etc.
Versuchen Sie dies in Ihrer .htaccess-Datei, beachten Sie dies nur funktioniert, wenn Sie mod_expires
haben und mod_headers
aktiviert in Apache:
<ifModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 seconds"
ExpiresByType text/html "access plus 1 seconds"
ExpiresByType image/gif "access plus 2592000 seconds"
ExpiresByType image/jpeg "access plus 2592000 seconds"
ExpiresByType image/png "access plus 2592000 seconds"
ExpiresByType text/css "access plus 604800 seconds"
ExpiresByType text/javascript "access plus 216000 seconds"
ExpiresByType application/x-javascript "access plus 216000 seconds"
ExpiresByType application/javascript "access plus 216000 seconds"
</ifModule>
<ifModule mod_headers.c>
<filesMatch "\\.(ico|pdf|flv|jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=2592000, public"
</filesMatch>
<filesMatch "\\.(css)$">
Header set Cache-Control "max-age=604800, public"
</filesMatch>
<filesMatch "\\.(js)$">
Header set Cache-Control "max-age=216000, private"
</filesMatch>
<filesMatch "\\.(xml|txt)$">
Header set Cache-Control "max-age=216000, public, must-revalidate"
</filesMatch>
<filesMatch "\\.(html|htm|php)$">
Header set Cache-Control "max-age=1, private, must-revalidate"
</filesMatch>
</ifModule>