[theme-reviewers] Integrating JavaScript

Sayontan Sinha sayontan at gmail.com
Fri Jul 15 16:13:26 UTC 2011

One simple scenario (which is not recommended for themes) is the explicit
de-registering of JQuery and registering a CDN version of it. Your
subsequent scripts enqueue JQuery, but you will need to explicitly register
the CDN version.

Here is another scenario:

   1. Let's say you are offering a handful of JS libraries A, B, C, D and E,
   of which A is a core dependency for all the others.
   2. Now consider that the A could have two variants - a heavyweight
   feature-rich one a-full.js, and a "lite" one a-lite.js. Which one you load
   depends on an option you set in the back-end.
   3. The dependent libraries can all operate using a-lite.js, but can
   operate just as well with a-full.js.

To handle this scenario you could have 2 approaches:

   1. Conditionally register a-full or a-lite depending on the option
   selection with the same handle (like "a-script"), then enqueue B, C, D and E
   with "a-script" as a dependency
   2. Do not assign the same handle, but write separate "if" conditions for
   each script. So you will register either a-script-full (for a-full.js) or
   a-script-lite (for a-lite.js), then for each of B, C, D and E you will
   enqueue with either a-script-full or a-script-lite as a dependency.

The first method above uses "register" and involves a few lines of code less
than the second, which only uses enqueue.

Hope this is clear.

On Fri, Jul 15, 2011 at 8:54 AM, esmi at quirm dot net <esmi at quirm.net>wrote:

> on 14/07/2011 13:14 Chip Bennett said the following:
>> Those scripts look fine to include; however, you will need to register and
>> enqueue them properly, using wp_register_script() and wp_enqueue_script(),
>> via a function hooked into the wp_enqueue_scripts hook.
> [Playing catch-up]
> This brings up a question that I'm pretty sure remained unanswered on the
> support forums. Is there any benefit to going through the full register then
> enqueue for a script compared to just dropping everything into an enqueue?
> Both methods seem to have equal weight in the Codex.
> Mel
> ______________________________**_________________
> theme-reviewers mailing list
> theme-reviewers at lists.**wordpress.org<theme-reviewers at lists.wordpress.org>
> http://lists.wordpress.org/**mailman/listinfo/theme-**reviewers<http://lists.wordpress.org/mailman/listinfo/theme-reviewers>

Sayontan Sinha
http://mynethome.net | http://mynethome.net/blog
Beating Australia in Cricket is like killing a celebrity. The death gets
more coverage than the crime.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.wordpress.org/pipermail/theme-reviewers/attachments/20110715/3acdb96d/attachment.htm>

More information about the theme-reviewers mailing list