Idealmente para mejorar la velocidad de la web, se puede permitir que el navegador no se descargue todos los ficheros cada vez y que ni siquiera consulte al servidor, si existe una nueva versión, en realidad, cambiaremos el nombre del fichero cuando haya una actualización de versión.

Para poder utilizar la configuración Expires hay que ‘unset’ los ETags, simplemente añadiendo el siguiente fragmento en el .htaccess que se suele encontrar en el directorio raíz(compatible con Apache y Litespeed web servers), añadiendo:

Header unset Pragma
FileETag None
Header unset ETag

Y un ejemplo de configuración de Expires, para insertar en el mismo .htaccess:

<IfModule mod_expires.c>
  ExpiresActive on
# Perhaps better to whitelist expires rules? Perhaps.
  ExpiresDefault                          "access plus 2 months"
# cache.appcache needs re-requests in FF 3.6 (thx Remy ~Introducing HTML5)
  ExpiresByType text/cache-manifest       "access plus 0 seconds"
# your document html
  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"
# rss feed
  ExpiresByType application/rss+xml       "access plus 1 hour"
# favicon (cannot be renamed)
  ExpiresByType image/x-icon              "access plus 1 week"
# media: images, video, audio
  ExpiresByType image/gif                 "access plus 2 months"
  ExpiresByType image/png                 "access plus 2 months"
  ExpiresByType image/jpg                 "access plus 2 months"
  ExpiresByType image/jpeg                "access plus 2 months"
  ExpiresByType video/ogg                 "access plus 2 months"
  ExpiresByType audio/ogg                 "access plus 2 months"
  ExpiresByType video/mp4                 "access plus 2 months"
  ExpiresByType video/webm                "access plus 2 months"
# htc files  (css3pie)
  ExpiresByType text/x-component          "access plus 2 months"
# webfonts
  ExpiresByType font/truetype             "access plus 2 months"
  ExpiresByType font/opentype             "access plus 2 months"
  ExpiresByType application/x-font-woff   "access plus 2 months"
  ExpiresByType image/svg+xml             "access plus 2 months
  ExpiresByType application/vnd.ms-fontobject "access plus 2 months"
# css and javascript
  ExpiresByType text/css                  "access plus 2 months"
  ExpiresByType application/javascript    "access plus 2 months"
  ExpiresByType text/javascript           "access plus 2 months"
  <IfModule mod_headers.c>
    Header append Cache-Control "public"
  </IfModule>
</IfModule>

Nota: Si al configurar la opción aparece en la página el siguiente error:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, admin@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.

Y en el log hay referencia al .htaccess, esto es debido a que hay que habilitar el módulo de Apache para la etiqueta Header, mod_headers:

sudo a2enmod headers

Después reiniciar Apache

service apache2 restart

 

 

 

Categorías: Web

Admin

Becommerce.es es una colección de mis notas a título personal, use at your own risk.

0 comentarios

Deja un comentario