← WordPress

Background Randómico Carregamento

Lida 3267 vezes

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

Eu coloquei num tema do wordpress, backgrounds randómicos através de php, só que estes aparecem 1 segundo (mais ou menos) depois da página carregar o resto, existe alguma forma de fazer com que carregue ao mesmo tempo, ou até antes?
Offline

surfrib 
Membro
Mensagens 213 Gostos 0
Troféus totais: 29
Trófeus: (Ver todos)
Windows User Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3 Level 2

metes o script php a carregar no inicio... mesmo no <head>
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

como assim?
Offline

cenourinha 
Elite
Mensagens 4094 Gostos 21
Troféus totais: 34
Trófeus: (Ver todos)
Mobile User Apple User Level 6 Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4

Isso não terá a ver com o próprio "carregamento" da página?
Offline

Diogo Pinto 
Administrador
Mensagens 4400 Gostos 371
Feedback +4

Troféus totais: 37
Trófeus: (Ver todos)
Avatar Search Level 6 Linux User Mobile User Super Combination Combination Topic Starter 50 Poll Votes 10 Poll Votes

Se as imagens tiverem todas em cache demora na mesma?
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

Isso não terá a ver com o próprio "carregamento" da página?

Acho que sim.

Se as imagens tiverem todas em cache demora na mesma?

Sim demora.

Já experimentei fundo sem tar randomico e fica acontece o mesmo... Será do que? Tenho o mesmo template noutro site e isso não acontece
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

Que soluções tenho??
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

A de colocar o script mais acima no código fonte parece-me a melhor solução.
Offline

Thomato 
Membro
Mensagens 4125 Gostos 3
Feedback +2

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

A de colocar o script mais acima no código fonte parece-me a melhor solução.
Exacto, porque quando o browser está a ler um site começa pela primeira linha de código. Por isso, quanto mais acima estiver, mais rápido carrega.
Offline

narg 
Membro
Mensagens 265 Gostos 0
Feedback +2

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

Meter o script php mais acima ??? no head ? julgo que não terá nada a haver, mas sim a forma como está a ser metido no html
se é no <body style="background....">

É preciso tambem ver se o script php não está a ler o ficheiro de imagem tipo <img src="imagem.php"> pois mitas vezes esses scripts não deixam o browser fazer cache das imagens, e o melhor é ter uma pasta com 10 imagens numeradas de 1 a 10 e meter <img src="/pasta/<?=$numerorandom?>.jpg"> pois assim o browser vai fazer cache das imagens.
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

Estou a usar este código e está a ser chamado pelo css

Código: [Seleccione]
<?php

$folder '.';

    
$extList = array();
$extList['gif'] = 'image/gif';
$extList['jpg'] = 'image/jpeg';
$extList['jpeg'] = 'image/jpeg';
$extList['png'] = 'image/png';

// --------------------- END CONFIGURATION -----------------------

$img null;

if (
substr($folder,-1) != '/') {
$folder $folder.'/';
}

if (isset(
$_GET['img'])) {
$imageInfo pathinfo($_GET['img']);
if (
    isset( $extListstrtolower$imageInfo['extension'] ) ] ) &&
        
file_exists$folder.$imageInfo['basename'] )
    ) {
$img $folder.$imageInfo['basename'];
}
} else {
$fileList = array();
$handle opendir($folder);
while ( false !== ( $file readdir($handle) ) ) {
$file_info pathinfo($file);
if (
    isset( $extListstrtolower$file_info['extension'] ) ] )
) {
$fileList[] = $file;
}
}
closedir($handle);

if (count($fileList) > 0) {
$imageNumber time() % count($fileList);
$img $folder.$fileList[$imageNumber];
}
}

if (
$img!=null) {
$imageInfo pathinfo($img);
$contentType 'Content-type: '.$extList$imageInfo['extension'] ];
header ($contentType);
readfile($img);
} else {
if ( function_exists('imagecreate') ) {
header ("Content-type: image/png");
$im = @imagecreate (100100)
    or die ("Cannot initialize new GD image stream");
$background_color imagecolorallocate ($im255255255);
$text_color imagecolorallocate ($im0,0,0);
imagestring ($im255,  "IMAGE ERROR"$text_color);
imagepng ($im);
imagedestroy($im);
}
}

?>
Offline

narg 
Membro
Mensagens 265 Gostos 0
Feedback +2

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

Esse script não permite aos browsers fazerem cache da imagem, limita-se a ler a imagem "readfile($img);" e botar cá para fora dizendo sempre ao browser para não fazer cache pois trata-se de um ficheiro .php
O melhor será colocar as imagens uma pasta /img por exemplo com os nomes 1.jpg 2.jpg 3.jpg e depois
Código: [Seleccione]
<?
$imagem = rand(1, 10); // imaginando que 10 é o numero máximo da imagem
?>
<body style="background-image:url('/img/<?=$imagem?>.jpg')">

Apagando assim o background no css, ou entar renomear o css para .css.php mas ai terá de se alterar o header para text/css