F
F
fanofthefate2016-05-27 14:13:32
htaccess
fanofthefate, 2016-05-27 14:13:32

Optimizing PageSpeed ​​Insights, how to increase caching time for images and documents in .htaccess file?

PageSpeed ​​Insights recommends increasing the caching time for images and files from 60 minutes to a higher value. I added the corresponding detectives to the HTACCESS file in the root folder of the site, but there is no result, why does the caching time not increase if all commands are registered?
.HTACCESS File Code
Header append Cache-Control "public, no-transform"
Header set Cache-Control "max-age=2592000, public"
Header set Cache-Control "max-age=2592000, public"
Header set Cache-Control " max-age=172800, public, must-revalidate"
Header set Cache-Control "max-age=172800, private, must-revalidate"
# ------------------------------------------------- ---------------------
# Force IE not to go into compatibility mode in some cases
# https://github.com/rails/rails/commit/123eb25#comm ...
# mod_headers doesn't know the content-type, but we only need to send this header for certain file types
Header unset X-UA-Compatible
# --------------- -------------------------------------------------- -----
# Cross-domain AJAX
# ----------------------------------------- -----------------------------
# Handling cross-domain Ajax requests, disabled by default.
# enable-cors.org
#code.google.com/p/html5security/wiki/CrossOriginRe...
#
# Header set Access-Control-Allow-Origin "*"
#
# ------------------ -------------------------------------------------- --
# Cross-origin images (CORS-enabled images) (@crossorigin)
# ---------------------------------- ------------------------------
# Send CORS headers, if the browser requires them, for default images included.
# developer.mozilla.org/en/CORS_Enabled_Image
# blog.chromium.org/2011/07/using-cross-domain-image...
# hacks.mozilla.org/2011/11/using-cors-to-load- webgl...
# wiki.mozilla.org/Security/Reviews/crossoriginAttribute
# mod_headers, why don't you define Content-Type?!
SetEnvIf Origin ":" IS_CORS
Header set Access-Control-Allow-Origin "*" env=IS_CORS
# ---------------------------- ------------------------------------------------
# Gzip compression
# ---- -------------------------------------------------- ----------------
# Enable deflate for non-standard headers:
# developer.yahoo.com/blogs/ydn/posts/2010/12/pushin...
SetEnvIfNoCase ^(Accept- EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4, 13}$ HAVE_Accept-Encoding
RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
AddOutputFilterByType DEFLATE text/html text/plain text/css \
application/json text/javascript application/javascript application/x-javascript text/x-js text/ecmascript application/ecmascript text/vbscript text/fluffscript \
text/xml application/xml text/x-component \
application/xhtml+xml application/rss+xml application/atom+xml \
image/x-icon image/svg+xml application/vnd.ms-fontobject application/x-font-ttf font/opentype
# -------------------------------------------------- --------------------
# Set Expires headers (file expiration date) (for better caching)
# --------------- -------------------------------------------------- -----
# Indicate headers with a long expiration date,
# this assumes you are using a cache based on filenames (all.css?v001).
# In addition, be aware that older proxies may not cache correctly
# www.stevesouders.com/blog/2008/08/23/revving-filen...
# If you don't use filenames for version control, change the CSS cache and JS, for example on
# "access plus 1 week".
ExpiresActive on
# Set default value (for all files)
ExpiresDefault "access plus 1 month"
# cache.appcache can't be cached in FF 3.6 (thanks Remy ~Introducing HTML5)
# Your html document
ExpiresDefault "access plus 0 seconds"
ExpiresByType text/html "access plus 0 seconds"
# Data
ExpiresByType text/xml "access plus 0 seconds"
ExpiresByType application/xml "access plus 0 seconds"
ExpiresByType application/json "access plus 0 seconds"
# Broadcast
ExpiresByType application/rss+xml "access plus 1 week"
ExpiresByType application/atom +xml "access plus 1 week"
# Favicon (cannot be renamed)
ExpiresDefault "access plus 1 week"
ExpiresByType image/x-icon "access plus 1 week"
# Media: images, video, audio
ExpiresDefault "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType video/ogg "access plus 1 year"
ExpiresByType audio/ogg "access plus 1 year"
ExpiresByType video/mp4 "access plus 1 year"
ExpiresByType video/webm "access plus 1 year"
# HTC files (css3pie)
ExpiresByType text/x-component "access plus 1 month"
# Web fonts
ExpiresDefault "access plus 1 year"
ExpiresByType application/x-font-ttf "access plus 1 month"
ExpiresByType font/opentype"access plus 1 month"
ExpiresByType application/x-font-woff "access plus 1 month"
ExpiresByType image/svg+xml "access plus 1 month"
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
# CSS and JavaScript
ExpiresDefault "access plus 1 year "
ExpiresByType text/css "access plus 1 year"
ExpiresByType application/javascript "access plus 1 year"
# Static resources
ExpiresDefault "access plus 1 year"
ExpiresByType application/x-shockwave-flash "access plus 1 year"
ExpiresByType application/pdf " access plus 1 year"
ExpiresByType application/msword"access plus 1 year"
ExpiresByType application/rtf "access plus 1 year"
ExpiresByType application/vnd.ms-excel "access plus 1 year"
ExpiresByType application/vnd.ms-powerpoint "access plus 1 year"
# ----------- -------------------------------------------------- ---------
# Remove ETag + Cache-Control
# --------------------------------- -------------------------------------
# FileETag None is not enough (for some servers).
Header unset ETag
# Since we're sending expires headers with a long expiration,
# we don't use ETag for static content.
# developer.yahoo.com/performance/rules.html#etags
FileETag None
## The browser should update the document after the time specified in seconds, which is set in the Cache-Control.
Header set Cache-Control "max-age=0, private, must-revalidate"
Header set Cache-Control "max-age=31556926, public"
Header set Cache-Control "max-age=31556926, public"
Header set Cache- Control "max-age=31556926, public"
Header set Cache-Control "max-age=31556926, public"
Header set Cache-Control "no-transform"
# --------------- -------------------------------------------------- -----
# Replace "www.example.com -> example.com".
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.
# ------------------------------------------------- ---------------------
# UTF-8 encoding
# ----------------------- ------------------------------------------------------
# Use UTF -8 encoding for all passed text/plain or text/html
AddDefaultCharset utf-8

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
fanofthefate, 2016-05-27
@fanofthefate

I noticed a dependency that files that contain the @ symbol in the name are not cached, example "[email protected]"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question