← WordPress

Isto pesa muito num site?

Lida 9613 vezes

Offline

Luís Salvador 
Membro
Mensagens 2068 Gostos 37
Feedback +4

Troféus totais: 28
Trófeus: (Ver todos)
Apple User Super Combination Combination Topic Starter Poll Voter Level 5 Level 4 Level 3 Level 2 Level 1

Pessoal, tenho que optimizar o meu site e poupar uns Gb's ao fim do mês. O meu site gasta 50gb de banda todos os meses e acho que isso é demasiado.

Um dos problemas é que tenho que fazer upload várias vezes da mesma imagem para poder anexá-las aos diversos posts e assim fazer aparecer os thumbnails no theme.

Em alternativa usaria um código assim:

Código: [Seleccione]
<?php if (is_category(22)) { ?>
<img src="http://ptwrestling.net/images/thumb_noticias.jpg" width="100" height="75" alt="<?php the_title(); ?>" title="<?php the_title(); ?>">
<?php } elseif (has_tag(43)) { ?>
<img src="http://ptwrestling.net/images/thumb_roh.jpg" width="100" height="75" alt="<?php the_title(); ?>" title="<?php the_title(); ?>">
<?php } elseif (has_tag(174)) { ?>
<img src="http://ptwrestling.net/images/thumb_vintagecollection.jpg" width="100" height="75" alt="<?php the_title(); ?>" title="<?php the_title(); ?>">
<?php } elseif (has_tag(313)) { ?>
<img src="http://ptwrestling.net/images/thumb_toughenough.jpg" width="100" height="75" alt="<?php the_title(); ?>" title="<?php the_title(); ?>">
<?php } elseif (has_tag(298)) { ?>
<img src="http://ptwrestling.net/images/thumb_semanadelucha.jpg" width="100" height="75" alt="<?php the_title(); ?>" title="<?php the_title(); ?>">
<?php } else { ?>
<?php get_thumbnail($post->ID'thumbnail''alt="' $post->post_title '"'); ?>
<?php ?>

Acham que este PHP todo pesa muito no servidor? Que acham?

Vale mais ter um código assim parecido para cada "tipo de post" que tenho ou anexar a mesma imagem N vezes por cada vez que faço um post com a Tag X ou Categoria Y ?
Offline

hpwd 
Membro
Mensagens 17 Gostos 0
Troféus totais: 17
Trófeus: (Ver todos)
Super Combination Combination Topic Starter Level 3 Level 2 Level 1 10 Posts First Post Karma Avatar

isso de peso não têm nada, mas uma coisa que estás a fazer mal é estar sempre a abrir/fechar "o php".
usa echo em vez de fechares o php para imprimires o que queres.

quanto à largura de banda que gastas, tenta optimizar as imagens, comprimir/unir ficheiros css e javascript.

se calhar já sabes isto mas cá vai na mesma:
quanto à optimização de imagens:
- no photoshop faz save for web and devices, sempre que puderes usa JPG's em vez de PNG's
- quando usares imagens, usa o tamanho certo em vez de incluíres uma imagem de 2000x2000 e depois no html teres <img src="" alt="" width="100" height="100" />

cumps ;)
Offline

euluism 
Membro
Mensagens 975 Gostos 0
Feedback +4

Troféus totais: 26
Trófeus: (Ver todos)
Super Combination Combination Topic Starter Poll Voter Level 5 Level 4 Level 3 Level 2 Level 1 500 Posts

isso de peso não têm nada, mas uma coisa que estás a fazer mal é estar sempre a abrir/fechar "o php".
usa echo em vez de fechares o php para imprimires o que queres.

quanto à largura de banda que gastas, tenta optimizar as imagens, comprimir/unir ficheiros css e javascript.

se calhar já sabes isto mas cá vai na mesma:
quanto à optimização de imagens:
- no photoshop faz save for web and devices, sempre que puderes usa JPG's em vez de PNG's
- quando usares imagens, usa o tamanho certo em vez de incluíres uma imagem de 2000x2000 e depois no html teres <img src="" alt="" width="100" height="100" />

cumps ;)

Existe a qualidade 12 do JPG... Passa a usar 8 ou 10 de 500 kb´s podes passar a 150 kb´s por imagem...
Offline

Luís Salvador 
Membro
Mensagens 2068 Gostos 37
Feedback +4

Troféus totais: 28
Trófeus: (Ver todos)
Apple User Super Combination Combination Topic Starter Poll Voter Level 5 Level 4 Level 3 Level 2 Level 1

Eu no Photoshop faço sempre Save For Web e uso Qualidade 50. Mais optimização de imagens está fora de questão ; )

As imagens já têm 100x75 (na realidade), eu é que coloco no html na mesma.

Quanto ao código em echo, vou experimentar a ver se consigo... Não vai dar problema por causa da última linha de PHP que tenho? Vou tentar... Consegues-me reescrever o código usando echo? :P
Offline

Fernando Augusto 
Membro
Mensagens 922 Gostos 0
Feedback +1

Troféus totais: 30
Trófeus: (Ver todos)
Linux User Mobile User Windows User Super Combination Combination Topic Starter Poll Voter Level 5 Level 4 Level 3

Combina os js todos ou a maior parte deles.

Código: [Seleccione]
http://ptwrestling.net/wp-content/plugins/contact-form-7/jquery.form.js?ver=2.52
    http://ptwrestling.net/wp-content/plugins/contact-form-7/scripts.js?ver=2.4.4
    http://ptwrestling.net/wp-content/plugins/featured-content-gallery/scripts/jd.gallery.js.php
    http://ptwrestling.net/wp-content/plugins/featured-content-gallery/scripts/jd.gallery.transitions.js
    http://ptwrestling.net/wp-content/plugins/featured-content-gallery/scripts/mootools.v1.11.js
    http://ptwrestling.net/wp-content/plugins/nextgen-gallery/js/jquery.cycle.all.min.js?ver=2.88
    http://ptwrestling.net/wp-content/plugins/nextgen-gallery/js/ngg.slideshow.min.js?ver=1.05
    http://ptwrestling.net/wp-content/plugins/nextgen-gallery/shutter/shutter-reloaded.js?ver=1.3.0
    http://ptwrestling.net/wp-content/plugins/wp-polls/polls-js.js?ver=2.50
    http://ptwrestling.net/wp-includes/js/jquery/jquery.js?ver=1.4.4
    http://ptwrestling.net/wp-includes/js/l10n.js?ver=20101110

Assim como os .css

Código: [Seleccione]
    http://ptwrestling.net/wp-content/plugins/contact-form-7/styles.css?ver=2.4.4
    http://ptwrestling.net/wp-content/plugins/featured-content-gallery/css/jd.gallery.css
    http://ptwrestling.net/wp-content/plugins/featured-content-gallery/css/jd.gallery.css.php
    http://ptwrestling.net/wp-content/plugins/nextgen-gallery/css/nggallery.css?ver=1.0.0
    http://ptwrestling.net/wp-content/plugins/nextgen-gallery/shutter/shutter-reloaded.css?ver=1.3.0
    http://ptwrestling.net/wp-content/plugins/wp-pagenavi/pagenavi-css.css?ver=2.70
    http://ptwrestling.net/wp-content/plugins/wp-polls/polls-css.css?ver=2.50
    http://ptwrestling.net/wp-content/themes/channel/style.css

Activa também a compressão Gzip para o site.

Aproveita e corre o Page Speed e analisa o que te dá
Offline

Luís Salvador 
Membro
Mensagens 2068 Gostos 37
Feedback +4

Troféus totais: 28
Trófeus: (Ver todos)
Apple User Super Combination Combination Topic Starter Poll Voter Level 5 Level 4 Level 3 Level 2 Level 1

Que plugin aconselhas para fazer a união dos .js e dos .css ? Este é bom: http://wordpress.org/extend/plugins/js-css-script-optimizer ?

Quanto ao Gzip, activo isso onde? Pelo .htaccess? Tens algum exemplo de um .htaccess "ideal"?

O Page Speed dá-me 81.
http://gtmetrix.com/reports/ptwrestling.net/k0Z01fj2
Offline

GhostMaster 
Membro
Mensagens 1374 Gostos 0
Feedback +10

Troféus totais: 26
Trófeus: (Ver todos)
Super Combination Combination Topic Starter Poll Voter Level 5 Level 4 Level 3 Level 2 Level 1 1000 Posts

Activar o cloudflare não poderá ser boa solução?
Offline

Carlos Gandra 
Administrador
Mensagens 3081 Gostos 97
Feedback +1

Troféus totais: 34
Trófeus: (Ver todos)
Level 6 Super Combination Combination Topic Starter 50 Poll Votes 10 Poll Votes Poll Voter Poll Starter Level 5 Level 4

Luís, precisas de todos esses JS e CSS para o site?

Seja como for, instala o W3 Total Cache se ainda não o fizeste, activa o Minify e adiciona lá todos os JS e todos os CSS:
 - Abre a página do site e vê o código fonte;
 - Copia todos os .js e .css
 - Remove os ?ver=x.xx
 - Adiciona os .css e os .js nas box's respectivas da configuração do plugin
 - Activa também a opção de remover os line breaks e os comments. Se por acaso o site deixar de funcionar bem, desactiva estas duas opções.

Em relação ao gzip, estás em partilhado ou VPS/Dedicado? O ideal é teres o mod deflate activo, mas em alojamento partilhado não sei que empresas eventualmente o disponibilizem. Com o mod deflate, depois no cPanel tens um ícone chamado "Optimizar website" onde podes activar a compressão para todo o conteúdo. E, por fim, adicionar estas regras ao .htacess (ponto 3).
Offline

Luís Salvador 
Membro
Mensagens 2068 Gostos 37
Feedback +4

Troféus totais: 28
Trófeus: (Ver todos)
Apple User Super Combination Combination Topic Starter Poll Voter Level 5 Level 4 Level 3 Level 2 Level 1

Preciso, fazem todos parte de plugins que tenho activos.

Quanto ao W3 Total Cache, o meu site é actualizado várias vezes ao dia... Isso não poderá fazer com que uma pessoa visite o site e esteja sempre a ver o mesmo cache e não as novidades? Uma vez experimentei o W3TC e não tive muita sorte nem soube bem como configurar...

O Minify já usei e se calhar vou mesmo voltar a experimentar.

Quanto ao gzip, isso do optimizar acho que não tenho.

O meu .htaccess neste momento está assim:

Código: [Seleccione]
# BEGIN WordPress

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

<ifModule mod_gzip.c>
  mod_gzip_on Yes
  mod_gzip_dechunk Yes
  mod_gzip_item_include file \.(html?|txt|css|js|php)$
  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_php4.c>
php_value zlib.output_compression 16386
</ifmodule>

FileETag MTime Size
<ifmodule mod_expires.c>
  <filesmatch "\.(jpg|gif|png|css|js)$">
       ExpiresActive on
       ExpiresDefault "access plus 1 week"
   </filesmatch>
</ifmodule>

AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch bMSIE !no-gzip !gzip-only-text/html

# Expire images header
ExpiresActive On
ExpiresDefault A0
ExpiresByType image/gif A2592000
ExpiresByType image/png A604800
ExpiresByType image/jpg A604800
ExpiresByType image/jpeg A604800
ExpiresByType image/ico A2592000
ExpiresByType text/css A604800
ExpiresByType text/javascript A2592000

FileETag None

# END WordPress
Offline

Luís Salvador 
Membro
Mensagens 2068 Gostos 37
Feedback +4

Troféus totais: 28
Trófeus: (Ver todos)
Apple User Super Combination Combination Topic Starter Poll Voter Level 5 Level 4 Level 3 Level 2 Level 1

Já alterei o .htaccess para isto:

Código: [Seleccione]
### BEGIN .htaccess
 
 # Protect the htaccess file
 <Files .htaccess>
  Order Allow,Deny
  Deny from all
 </Files>
 
 # Protect wpconfig.php
 <Files wp-config.php>
  Order Allow,Deny
  Deny from all
 </Files>
 
 # Disable directory browsing
 Options All -Indexes
 
 # BEGIN COMPRESSION AND CACHING
 <IfModule mod_deflate.c>
  # Enable compression
  AddOutputFilterByType DEFLATE text/css text/javascript application/x-javascript text/html text/plain text/xml image/x-icon
  <IfModule mod_setenvif.c>
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
  BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
  </IfModule>
  <IfModule mod_headers.c>
  # Make sure proxies deliver correct content
  Header append Vary User-Agent env=!dont-vary
  # Ensure proxies deliver compressed content correctly
  Header append Vary Accept-Encoding
  </IfModule>
 </IfModule>
 <IfModule mod_headers.c>
  # No ETags, No Pragma
  Header unset Pragma
  Header unset ETag
  # Default cache time to 1 year (31536000 sec)
  Header set Cache-Control "max-age=31536000, public, must-revalidate"
 </IfModule>
 <IfModule mod_gzip.c>
  mod_gzip_on Yes
  mod_gzip_dechunk Yes
  mod_gzip_item_include file \.(html?|xml|txt|css|js)$
  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>
 
 # No ETags
 FileETag none
 
 # CACHE SETTINGS (mod_expires)
 <IfModule mod_expires.c>
  # Turn on Expires
  ExpiresActive On
  # set default to "access plus 1 year"
  ExpiresDefault A31536000
  # html - "modification plus 1 hour"
  ExpiresByType text/html M3600
  # css and JavaScript - "modification plus 6 weeks"
  ExpiresByType text/css M3628800
  ExpiresByType text/javascript M3628800
  ExpiresByType application/x-javascript M3628800
 </IfModule>
 # No cache for php-files
 <FilesMatch "\.(php)$">
  <IfModule mod_expires.c>
  ExpiresActive Off
  </IfModule>
  <IfModule mod_headers.c>
  Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform"
  </IfModule>
 </FilesMatch>
 # END CACHING
 
 # W3 Total Cache are here (automatically included by the plugin):
 
 # WordPress Default Rules are here (at the end of the file):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
 
 ### END .htaccess

Quanto aos plugins, já activei. Falta configurar... ; )
Offline

Carlos Gandra 
Administrador
Mensagens 3081 Gostos 97
Feedback +1

Troféus totais: 34
Trófeus: (Ver todos)
Level 6 Super Combination Combination Topic Starter 50 Poll Votes 10 Poll Votes Poll Voter Poll Starter Level 5 Level 4

Quanto ao W3 Total Cache, o meu site é actualizado várias vezes ao dia... Isso não poderá fazer com que uma pessoa visite o site e esteja sempre a ver o mesmo cache e não as novidades?

Depende do valor de expiração que coloques na configuração do plugin ;) Penso que por defeito vem 1 hora (3600), reduz para metade ou até para uns 10 minutos, conforme achares melhor.
Offline

Luís Salvador 
Membro
Mensagens 2068 Gostos 37
Feedback +4

Troféus totais: 28
Trófeus: (Ver todos)
Apple User Super Combination Combination Topic Starter Poll Voter Level 5 Level 4 Level 3 Level 2 Level 1

W3TC activado e a funcionar! (tirei o WP Minify, já que este inclui essa opção)

O .htaccess já está bastante extenso (foi o W3TC que o pôs assim).

Acho que já está mais optimizadinho. Se alguém que perceba da coisa quiser testar: http://ptwrestling.net

; )
Offline

Carlos Gandra 
Administrador
Mensagens 3081 Gostos 97
Feedback +1

Troféus totais: 34
Trófeus: (Ver todos)
Level 6 Super Combination Combination Topic Starter 50 Poll Votes 10 Poll Votes Poll Voter Poll Starter Level 5 Level 4

Se tiveres colocado as regras do link que te dei, desactiva o Browser cache no plugin, vão dar ao mesmo mas as do link são melhores ;)
Offline

Miguel Patrício 
Membro
Mensagens 445 Gostos 9
Feedback +1

Troféus totais: 27
Trófeus: (Ver todos)
Tenth year Anniversary Super Combination Combination Topic Starter Poll Voter Level 5 Level 4 Level 3 Level 2 Level 1

Em relação ao "peso" das imagens, recomendo que instales o plugin WP Smush.it.
Esse plugin comprime automaticamente as imagens sem perda de qualidade.
É instalar e esquecer.

Experimenta.
Offline

Luís Salvador 
Membro
Mensagens 2068 Gostos 37
Feedback +4

Troféus totais: 28
Trófeus: (Ver todos)
Apple User Super Combination Combination Topic Starter Poll Voter Level 5 Level 4 Level 3 Level 2 Level 1

As imagens já não podem ficar a pesar menos se não perdem a qualidade praticamente toda, já estão como .jpg com quality 50 (em 100).

Se tiveres colocado as regras do link que te dei, desactiva o Browser cache no plugin, vão dar ao mesmo mas as do link são melhores ;)

Ok, done. Já agora, quais são as que coloco Enable? Para já só tenho a Page Cache e Minify...

------

Na minha questão inicial só queria saber se aquele PHP todo pesava ou não muito no site:

Código: [Seleccione]
<?php if (is_category(22)) { ?>
<img src="http://ptwrestling.net/images/thumb_noticias.jpg" width="100" height="75" alt="<?php the_title(); ?>" title="<?php the_title(); ?>">
<?php } elseif (has_tag(43)) { ?>
<img src="http://ptwrestling.net/images/thumb_roh.jpg" width="100" height="75" alt="<?php the_title(); ?>" title="<?php the_title(); ?>">
<?php } elseif (has_tag(174)) { ?>
<img src="http://ptwrestling.net/images/thumb_vintagecollection.jpg" width="100" height="75" alt="<?php the_title(); ?>" title="<?php the_title(); ?>">
<?php } elseif (has_tag(313)) { ?>
<img src="http://ptwrestling.net/images/thumb_toughenough.jpg" width="100" height="75" alt="<?php the_title(); ?>" title="<?php the_title(); ?>">
<?php } elseif (has_tag(298)) { ?>
<img src="http://ptwrestling.net/images/thumb_semanadelucha.jpg" width="100" height="75" alt="<?php the_title(); ?>" title="<?php the_title(); ?>">
<?php } elseif (has_tag(81)) { ?>
<img src="http://ptwrestling.net/images/thumb_wp.jpg" width="100" height="75" alt="<?php the_title(); ?>" title="<?php the_title(); ?>">
<?php } elseif (has_tag(83)) { ?>
<img src="http://ptwrestling.net/images/thumb_wsw.jpg" width="100" height="75" alt="<?php the_title(); ?>" title="<?php the_title(); ?>">
<?php } elseif (has_tag(84)) { ?>
<img src="http://ptwrestling.net/images/thumb_apw.jpg" width="100" height="75" alt="<?php the_title(); ?>" title="<?php the_title(); ?>">
<?php } elseif (has_tag(70)) { ?>
<img src="http://ptwrestling.net/images/thumb_ufc.jpg" width="100" height="75" alt="<?php the_title(); ?>" title="<?php the_title(); ?>">
<?php } else { ?>
<?php get_thumbnail($post->ID'thumbnail''alt="' $post->post_title '"'); ?>
<?php ?>

Isto porque todos os posts dessas Tags têm um thumbnail fixo e sempre igual, os outros é que já têm um personalizado a cada post (penúltima linha do código).