Trucos » Optimizar tu sitio y acelerar la carga web

Con estos sencillos trucos tu sitio web cargará más rápido y tus usuarios te lo agreceran

Si eres como yo que no me importa como se vea el código HTML en el browser, comprimelo al máximo eliminando los espacios innecesarios, y modificando el HEADER.

Coloca esto al principio de la página:

<?php
// NO TOCAR
header('Accept-Ranges: bytes');
$ExpStr = 'Expires: '.gmdate("D, d M Y H:i:s", time() + 14400) . " GMT"; // 14400 = 4 horas
header($ExpStr);
header("Cache-Control: maxage=14400");
header("Cache-Control: public, must-revalidate");
header("Cache-Control: public");
header("pragma: public");
header("Content-Transfer-Encoding:gzip;q=1.0,identity;q=0.5,*;q=0");
header("Cache-Control: cache");
header("Pragma: cache");
header('Content-Type: text/html; charset=iso-8859-1');
setlocale(LC_TIME, 'es_VE'); # Localiza en español es_Venezuela
// FIN NO TOCAR
// elimina los espacios en blanco
function compress_page($buffer) { $search = array('/\>[^\S ]+/s','/[^\S ]+\</s','/(\s)+/s'); $replace = array('> ',' <','\\1'); return preg_replace($search, $replace, $buffer); }
ob_gzhandler(ob_start("compress_page"));
?>

Y al final luego del tag<html>:

<?php ob_end_flush(); ?>

Al usar archivos .htaccess se maximiza la carga (más sobre los .htaccess en Apache). 

<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault A86400
ExpiresByType image/x-icon A2592000
ExpiresByType application/x-javascript A2592000
ExpiresByType text/css A2592000
ExpiresByType image/gif A604800
ExpiresByType image/png A604800
ExpiresByType image/jpeg A604800
ExpiresByType text/plain A604800
ExpiresByType application/x-shockwave-flash A604800
ExpiresByType video/x-flv A604800
ExpiresByType application/pdf A604800
ExpiresByType text/html A900
</IfModule>
#Header
<IfModule mod_headers.c>
# YEAR
<FilesMatch "\.(ico|gif|jpg|jpeg|png|flv|pdf)$">
Header set Cache-Control "max-age=29030400"
</FilesMatch>
# WEEK
<FilesMatch "\.(js|css|swf)$">
Header set Cache-Control "max-age=1604800"
</FilesMatch>
# 45 MIN
<FilesMatch "\.(html|htm|txt)$">
Header set Cache-Control "max-age=2700"
</FilesMatch>
<FilesMatch "\.(xml|txt|html)$">
ExpiresDefault A71400
Header append Cache-Control "private, must-revalidate"
</FilesMatch>
</IfModule>
################## GZip Files ###################
<FilesMatch "\.js$">
AddHandler application/x-httpd-php .js
php_value default_mimetype "text/javascript"
</FilesMatch>
<FilesMatch "\.css$">
AddHandler application/x-httpd-php .css
php_value default_mimetype "text/css"
</FilesMatch>
<FilesMatch "\.(htm|html|shtml)$">
AddHandler application/x-httpd-php .html
php_value default_mimetype "text/html"
</FilesMatch>
# ejemplo: /var/www/vhosts/tu_sitio/httpdocs/gzip.
php_value auto_prepend_file ruta_real_de_tu sitio_/gzip.php

el código del archivo gzip.php

<?php
 if(isset($_SERVER['HTTP_ACCEPT_ENCODING']) && substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start('ob_gzhandler'); else ob_start();
 ?> 

Para observar si en verdad mejora, prueba en estas páginas la carga de tu sitio, y luego de hacer los cambios prueba de nuevo, observarás gran mejora.

  1. http://www.webpagetest.org/test RECOMENDADO
  2. http://www.jpwebsystems.com/utilidades-web.php
  3. http://www.velocidadtotal.com/es/speed_test.html
  4. http://analyze.websiteoptimization.com/ Importante
  5. http://webwait.com/ útil

Además hay que tener en cuenta algunos otros detalles:

Dale una mirada a este enlace: High Performance Web Sites.

También sería bueno añadir en el .htacces lo siguiente:

# evita el User-Agent libwww-perl

RewriteEngine on RewriteCond %{HTTP_USER_AGENT} libwww [NC,OR]
RewriteCond %{QUERY_STRING} ^(.*)=http [NC] RewriteRule ^(.*)$ – [F,L]

# mejora el mime para el expire

RewriteRule (.*)-cb\d+\.(.*)$ $1.$2 [L]

Best Practices for Speeding Up Your Web Site
http://developer.yahoo.com/performance/rules.html

Estos consejos te ayudaran a mejorar el rendimiento de carga de tu sitio web hasta en un 20% lo que tus usuarios lo agradeceran.

Fuente:
http://www.xombra.com

xombra

Publicado el 20 de Julio del 2010 por xombra

2298 visitas, 1 mensaje y 6 ediciones

Mensajes

Diego Escares Diego Escares el 20 de Julio del 2010: 0

Uf, edité bastante y encuentro que queda mejor. Quizás le falta más organización, hay muchos enlaces repartidos por el artículo.

¡Amigo! te demorarás 10 segundos en crear tu cuenta.

Disfrutarás de todos los beneficios de DocumentoWeb.

Twitter Twitter Facebook Facebook Feed RSS Feed RSS

www.DocumentoWeb.com Licencia Creative Commons