Wenn ich die Website mit yahoo YSLOW testet sagt es über massage.So weiß ich nicht, wie man ablauf headers.any Hilfe würde geschätzt werden?hinzufügen läuft Kopfzeilen ab
Antwort
Die einfachste Möglichkeit zum Hinzufügen dieser Header ist eine .htaccess
Datei, die Ihrem Server einige Konfigurationen hinzufügt. Wenn die Assets auf einem Server gehostet werden, den Sie nicht kontrollieren, können Sie nichts dagegen tun.
Beachten Sie, dass einige Hosting-Provider Sie nicht .htaccess
Dateien verwenden können, überprüfen Sie daher ihre Bedingungen, wenn es nicht zu funktionieren scheint.
Das HTML5Boilerplate-Projekt verfügt über eine ausgezeichnete .htaccess
Datei, die die erforderlichen Einstellungen umfasst. Siehe den entsprechenden Teil der Datei an ihrem Github repository
Dies sind die wichtigen Bits
# ----------------------------------------------------------------------
# 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>
Sie documented what that file does haben, ist das wichtigste Bit ist, dass Sie Ihre CSS und Javascript-Dateien umbenennen müssen, wenn sie sich ändern, denn Die Browser Ihres Besuchers überprüfen sie nicht erneut für ein Jahr, sobald sie zwischengespeichert sind.
möchte ich den vollständigen Code zu Htaccess im Github hinzufügen – sami
Nein, nur der Abschnitt "Läuft Kopfzeilen ab". Oder auch nur der Teil, den ich in meine Antwort eingefügt habe. Bitte stellen Sie sicher, dass Sie vollständig verstehen, was es tut, insbesondere warum [Cache-Busting] (https://github.com/h5bp/html5-boilerplate/blob/v4.0.2/doc/htaccess.md#cache-busting) einmal benötigt wird Du benutzt das. – pixelistik
Ich habe noch eine Frage. Kannst du mir eine Antwort geben? – sami
Sie können sie in Ihrer htaccess-Datei oder Vhost-Konfiguration hinzufügen.
Siehe hier: http://httpd.apache.org/docs/2.2/mod/mod_expires.html
Aber wenn Sie diese Domains besitzen .. sie unsere Ihrer Kontrolle.
diese Lösung versuchen und es funktioniert für mich
feinen## 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 ##
<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>
- 1. Nginx läuft auf Bildern ab - Subdir Override läuft ab
- 2. Xcode-Bereitstellungsprofil läuft ab
- 3. Läuft Viewstate ab?
- 4. Hinzufügen von Kopfzeilen auf JavaScript
- 5. Wann läuft ein NSURLRequest ab?
- 6. Android Service läuft nicht ab
- 7. Wie läuft redis Schlüssel ab?
- 8. Schienen - Fragmentcache läuft nicht ab
- 9. Hinzufügen von Kopfzeilen bei Verwendung von httpClient.GetAsync
- 10. ExtJS - Hinzufügen von Kopfzeilen zu AJAX-Shop
- 11. Hinzufügen von Kopfzeilen in ASP.NET MVC 3
- 12. HttpModule zum Hinzufügen von Kopfzeilen zur Anfrage
- 13. Hinzufügen von Kopfzeilen zu ORION-Anfragen
- 14. Hinzufügen von Kopfzeilen in Java Websocket-Client
- 15. Hinzufügen von benutzerdefinierten Kopfzeilen in allen Browsern
- 16. Nginx nicht Einstellung läuft Kopfzeilen auf Rails statische Assets
- 17. ADFS-Sitzung läuft ab und verursacht Fehler
- 18. App schläft nicht nach LeerlaufTimerzeit läuft ab
- 19. Google OAuth2 Refresh_token läuft ab, wenn Access_token
- 20. azureAD refreshtoken läuft in 14 Tagen ab
- 21. Facebook Grafik API-Version läuft ab
- 22. XAP läuft nach einem halben Tag ab?
- 23. URLConnection.setUseCaches (true) - Wann läuft der Cache ab?
- 24. Login-AzureRMAccount -Credential läuft sofort ab
- 25. Wie läuft der Cookie ordnungsgemäß ab?
- 26. Mokkentest läuft auf MEAN-Stack ab
- 27. SSL-Zertifikat läuft ab, während verbunden
- 28. Wie Kopfzeilen nur bestimmten Dateien mit Nginx hinzufügen
- 29. Verwendung von Interceptor zum Hinzufügen von Kopfzeilen in Retrofit 2.0
- 30. Android: Hinzufügen von statischen Kopfzeilen an den Anfang einer ListActivity
hoffen ther documenattion in ihrer Website –
Google 'PHP Add Verfällt headers' –
wäre ich, dass' static.doers gehe davon aus. lk' ist deine eigene Website? –