[wp-hackers] Optimize wp_register_script and wp_enqueue_script functions
Chip Bennett
chip at chipbennett.net
Wed Jan 25 23:28:19 UTC 2012
Presumably, you're putting your wp_register_script() and
wp_enqueue_script() calls inside a callback function, hooked into e.g.
wp_enqueue_scripts.
If so, simply wrap your wp_register_script() and/or wp_enqueue_script()
calls inside an appropriate conditional, such as if ( is_category() ).
Also note that, as of WordPress 3.3, inline script enqueueing is now
supported. (I've not used this feature, so I don't know the details.)
Chip
On Wed, Jan 25, 2012 at 5:24 PM, zhaiziming at gmail.com
<zhaiziming at gmail.com>wrote:
> Hey all,
>
> As I know, most of the plugins use wp_register_script() and
> wp_enqueue_script() to add js files into frontend pages. The current
> functionality will affect page load speed if you use many plugins. The
> problem is if you enqueue a js file, it will add this file to all the
> frontend pages, no matter if it is been used in these pages or not.
> For example, I add a plugin to vote categories which has two script files.
> They should be only been added in the category page, but turn out wordpress
> adds to all the pages like index, post and page. It is not good for site
> performance.
> My current solution is to write a function to deregister all the scripts
> and add them back on different pages, and then hook this function to init
> action.
>
> It would be great if wp_register_script and wp_enqueue_script have the
> feature to target the script to specific pages. Ultimately, it would be
> even great if wordpress support javascript lazy load (on demand). I am sure
> we will get a lot of performance benefits from it.
>
>
> Any suggestions and comments?
>
>
> James
> zhaiziming at gmail.com
> ______________________________**_________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.**com <wp-hackers at lists.automattic.com>
> http://lists.automattic.com/**mailman/listinfo/wp-hackers<http://lists.automattic.com/mailman/listinfo/wp-hackers>
>
More information about the wp-hackers
mailing list