Timeline for Enqueue CSS and Script only if needeed
Current License: CC BY-SA 4.0
13 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Nov 8, 2018 at 6:14 | comment | added | Remzi Cavdar | @Revious See my answer: wordpress.stackexchange.com/a/317186/149484 | |
Nov 7, 2018 at 22:15 | comment | added | sandrodz | @KrzysiekDróżdż Did I say it was easy? yes you first register assets, then enqueue. | |
Nov 7, 2018 at 20:50 | comment | added | Krzysiek Dróżdż | @Revious still, combine and minify - it will save lot more bandwidth and requests than loading different set of files... | |
Nov 7, 2018 at 20:49 | comment | added | Revious | @KrzysiekDróżdż: I'd like also to ask about a small issue.. I'm trying with Breeze caching and it dowsnt minify the css files.. if I cannot solve can I open a new questione and ask for help? | |
Nov 7, 2018 at 20:45 | comment | added | Revious | @KrzysiekDróżdż: yes, maybe with minification is doesn't make a big difference. However the browser cache doesn't help that much, in a real production scenario, since 80% of visitors are "non returning" and see 1,3 pages.. | |
Nov 7, 2018 at 20:43 | history | edited | Krzysiek Dróżdż | CC BY-SA 4.0 |
edited body
|
Nov 7, 2018 at 20:42 | comment | added | Krzysiek Dróżdż | @Revious You can achieve that, but it doesn't make much sense. CSS/JS files should be cached by browsers. Also, they should get combined and minified, so loading different set of JS/CSS files on different pages is rather harmful for performance. | |
Nov 7, 2018 at 20:41 | comment | added | Krzysiek Dróżdż | @sandrodz it's not so easy, because you have to enqueue script/style before it is printed (styles should be printed in header, and shortcodes are processed after header is printed). | |
Nov 7, 2018 at 20:21 | comment | added | Revious | I've found a similar solution here: wordpress.stackexchange.com/a/191316/64590 | |
Nov 7, 2018 at 20:17 | comment | added | Revious | @sandrodz: thanks. I just realized that 99% of WP plugin developers ignore this? Or don't they care about performance? Why to load JS or CSS when not needed? | |
Nov 7, 2018 at 19:23 | comment | added | sandrodz |
Yes, you can wp_enqueue_script() asset in your shortcode method/function. So only when shortcode is used, asset loads.
|
|
Nov 7, 2018 at 18:32 | history | edited | fuxia♦ | CC BY-SA 4.0 |
edited tags; edited title
|
Nov 7, 2018 at 16:54 | history | asked | Revious | CC BY-SA 4.0 |