WordPress.org

Ready to get started?Download WordPress

Forums

A plugin to detect javascript duplicates? (6 posts)

  1. googlebot
    Member
    Posted 6 years ago #

    I have few plugins active and I noticed that some of them add to the header the same javascript multiple times, for instance, I have scriptacolous referenced 3 times by 3 different plugins. Wouldn't that slow down a bit the loading time?
    Is that a normal behavior?

    So, I was wondering if there is any plugin to do a clean up in the header, detects any javascript duplicate and removes it.

    Thanks

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    WordPress itself eliminates these duplicates, in the latest versions. Of course, this is assuming that these plugins are correctly using the WP_Script functions.

    Basically, a plugin can add a javascript to WordPress, tell it what dependencies the script has (on other scripts), etc. Like if you have a JS that needs scriptaculous, you can add that script and tell WordPress that it needs scriptaculous. Then, you can "enqueue" it when you need it. WordPress will automatically output the necessary script tags to load the script into the page, along with it's dependencies.

    In other words, tell the plugin authors to fix their plugins to use the new WordPress functionality that was developed specifically to prevent this sort of thing. Scriptaculous and jQuery are both included in the latest WordPress, they don't need to be including them with their plugins anymore, they should use the existing versions by using the wp_enqueue_script functionality.

    Also, if you find a plugin that is not using this functionality and is loading it's own javascript directly, then please post it and tell everybody, because this means that it's likely *not* wholly compatible with the latest versions of WordPress (2.2 and up).

  3. googlebot
    Member
    Posted 6 years ago #

    Awesome, thanks.

  4. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    Since it's not documented particularly well, I added some starter documentation to the codex, so that people can figure out how to use the scripts functionality:
    http://codex.wordpress.org/Function_Reference/wp_enqueue_script

  5. imagiscapeca
    Member
    Posted 6 years ago #

    I can see which scripts are called, but I can't see which plugins are calling them!

    How can I find which plugin is calling the script?

    I have Firefox Extensions:

    • JSView (!)
    • Web Developer
    • Firebug
    • ViewSourceWith
    • View Source Chart

    I hope to find not only which plugins call jsquery, but ALSO which call it in the wrong way that leads to duplicate loads.

    If I search all my plugins' code, is there a tell-tale sign of incorrect code?

    Thanks

  6. imagiscapeca
    Member
    Posted 6 years ago #

    Still seeking ...

Topic Closed

This topic has been closed to new replies.

About this Topic