Is there any real benefit to using wp_enqueue_script on small self-managed sites? For instance, Modernizr, why enqueue it through a function rather than call it directly inside the document head?

I can see the benefit on large sites, where you may move around directories or have multiple people mucking around in the files, or in a publicly available theme with numerous unknowns, but what's the benefit on a small site like a personal blog that never - or rarely - changes and has a single user? It just seems like extra lines of code in that case.

2 Answers 2

  1. Are you using a Theme that you control?

    If not, then every time the Theme updates, you'll lose your modifications to the header. Or else, you'll have to fork the Theme, or maintain/backport your changes every time the Theme updates.

  2. Do you only use Plugins under your control?

    If not, then you'll have to check for script conflicts every time you activate or update a Plugin that uses a script.

  3. Are you using a core-bundled script?

    If so, then you'll have to check for core script conflicts every time you update core, as well as every time you update a Plugin that enqueues a core-bundled script.

  4. Do you use a caching Plugin?

    If so, then you lose some or all of the benefits of script concatenation/minimizing/caching, since your script is hard-coded in the document head rather than enqueued.

  • That pretty much covers it. I'm currently using 'enqueue' but I just find it...I don't know...unnecessary in this instance. Overkill? I don't know, every time I see it lately I'm find myself trying to justify it.
    – TinySites
    Apr 15, 2012 at 18:25
  • 2
    Damn Chip I tried to beat you to the punch with my fancy title ;)
    – Wyck
    Apr 15, 2012 at 21:22
  • How does Wordpress check for script conflicts? Does it require that you use some predefined handle when you register common, widely used scripts? aka does it require that you don't just invent your own handle names? Otherwise, how would it know my script from Adam or have any idea what conflicts my script might introduce? I guess in the right scenario, WP could also recognize the URL/filename for a script and know what it is. Dec 4, 2015 at 11:50

1. It only loads scripts when needed

Important for load speed.

2. It safely handles dependencies.

Reduces errors, duplicate loading and js clashing.

3. It handles load order and placement

Tell it where to load and when.

4. Its handles $src properly

Moving the site around, perfect.

5. It has versioning

Helps with caching and ..well versioning.

The "extra lines of code" is irrelevant, especially compared to the benefits of doing it right.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.