Home › Forum › Problemi Vari con WP › Caricare JS e CSS solo nelle pagine in cui servono
-
AutorePost
-
-
23 Marzo 2016 alle 15:13 #30730MarcoRM69Partecipante
Salve a tutti.
Sono nuovo e neofita di wordpress, me la cavicchio invece con php, css & Co.
Ho cercato ma non ho trovato una risposta alla mia domanda.
Ho trasformato da poco il mio vecchio sito in un blog wordpress (su altervista, lo so, non è il massimo ma per ora quello c’è).
Ho notato, anche utilizzando diverse risorse online, una certa lentezza nel caricamento, sopratutto della Home. Essendo un blog fotografico è chiaro che sia più pesante del normale a causa delle foto ma sono altri i problemi emersi.
Fermo restando che sto cercando di ottimizzare il blog secondo quanto letto su vari siti e forum. dai tool usati (in particolare pingdom), sembra che gran parte del tempo di caricamento sia dovuto alla presenza di CSS e JS, il problema è che (parlo della Home ad esempio) tanti di quei CSS e JS non servono sulla home (ad esempio quelli relativi ai plugin per i commenti o per gli articoli correlati, che uso solo all’interno degli articoli stessi).
C’è un modo per caricare, nelle varie pagine, solo quelli utili al funzionamento della pagina stessa?
Il blog è questo ( http://marcomiserini.altervista.org/ )
Grazie mille.
Marco.
-
23 Marzo 2016 alle 15:21 #120178wollyAmministratore del forum
ci sono tutti i tag condizionali http://codex.wordpress.org/it:Tag_condizionali
-
23 Marzo 2016 alle 15:38 #120179MarcoRM69Partecipante
Ah, ok. qualcuno lo conoscevo e l’ho usato per modificare alcuni template del tema.
Quindi devo capire dove è la parte di codice dove vengono inserite le righe di caricamento per i vari oggetti del plugin ed aggiungere i vari tag condizionali per decidere cosa e dove caricare.
Niente metodi meno “invasivi” o più automatici insomma
Thanks.
Marco
-
24 Marzo 2016 alle 7:14 #120187MarcoRM69Partecipante
Piccolo aggiornamento, magari può interessare qualche neofita come me.
Ho scoperto che i plugin vengono “caricati” da loro stessi attraverso la funzione wp register script.
Quindi o si modifica il plugin stesso o si può fare poco a quanto ho capito, sia per il caricamento, sia per la posizione di caricamento, diversi tool infatti indicano un problema sulla posizione dei javascript presenti nella pagina, consigliando di caricarli in fondo in quanto rischiano di bloccare il cosidetto above-the-fold.
Il rischio di modificare il plugin stesso è che (molto probabilmente) le modifiche si perdono al primo aggiornamento del plugin e andrebbero reinserite. Una scocciatura.
Comunque continuo a cercare metodi alternativi
Saluti.
Marco
-
24 Marzo 2016 alle 7:20 #120188wollyAmministratore del forum
Puoi deregistrarli e riregsitrarli quando ti servono, senza modificare i plugin.
Crei un plugin ad hoc per quello.
-
25 Marzo 2016 alle 14:47 #120202MarcoRM69Partecipante
Ciao.
Si ho trovato questa possibilità girando in rete.
In realtà ho provato creando un child theme (considerando anche che ho apportato modifiche al tema principale) e aggiunto, come consigliato da diversi blog, la deregistrazione nel functions.php del child, ma sembra non funzionare, i css e i js continuano ad essere caricati ovunque.
Sbaglio sicuramente qualcosa da qualche parte.
Continuo a provare.
Ciao,
Marco
-
25 Marzo 2016 alle 19:15 #120203TittiModeratore
Sbaglio sicuramente qualcosa da qualche parte.
Magari facci vedere cos’hai scritto
-
29 Marzo 2016 alle 6:22 #120208MarcoRM69Partecipante
Scusate il ritardo, sono stato un po’ impegnato in questi giorni.
Ok, datemi pure dell’idiota non funzionava perché avevo scritto male il nome del file!!!
Avevo creato il function.php invece del functions.php!!!! Non lo vedevo perché mi concentravo sul codice!
Ora funziona.
Ho un altro dubbio/problema, ma apro un altro topic visto che l’argomento è diverso.
Grazie a tutti!
-
-
AutorePost
- Devi essere connesso per rispondere a questo topic.