[wp-hackers] Optimize wp_register_script and, wp_enqueue_script functions

zhaiziming at gmail.com zhaiziming at gmail.com
Thu Jan 26 18:18:22 UTC 2012

Thank you for both comments. The problem of these solutions is that developer or blogger have to go through the plugin code and write a filter function by themselves. The shortcode solution is better, but in some cases you can't put all js files in the footer.
Would be better to let plugin authors to do this, and bind (or register) js files to specific pages not all?


Ziming Zhai

On 1/25/12 6:24 PM,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?
Here's an excellent article from Scribu:


- Jackson

More information about the wp-hackers mailing list