How to avoid loading same script twice?

  1. You can use a prefix like ‘xyz-‘ (basically a namespace) for the handle if the script or stylesheet you use is unique to your theme / plugin. Owl Carousel is not, so just ‘owlcarousel’ is fine. You’d use a prefix if you didn’t want any chance another loaded plugin might be using the same name for their script, causing yours not to load.

(As an aside, here is a list of WordPress’s default scripts, and the handles used for them, down the page a bit).

  1. Only the first encountered script with a particular handle is used. Any further attempts to enqueue something with the same handle are ignored (reference: notes for wp_enqueue_script). If you needed to specifically use your particular script for a particular handle (e.g. loading a special version of jQuery, and not using WordPress’s built-in version), you’d have to deregister the existing one and then register/enqueue yours.

  2. How scripts deal with being loaded multiple times is script-dependent. If a conflict was likely, you could try loading a particular script, such as Owl Carousel, twice (with different handles), and see if it still works okay. Wouldn’t it be nice if everyone used a commonly-agreed list of handles for things like Owl Carousel. 🙂

  3. The same rules/effects apply to CSS stylesheets.