Benefits to enqueuing site scripts/stylesheets?

I’m aware of a similar question here: What are the benefits of using wp_enqueue_script? –

However, what differs is I’m talking about a site with a pre concatenated/minified stylesheet and site scripts. I only load two js files and one css file. The two JS files are main.js (which contains all general scripts such as toggles, etc) and plugins.js which contains all js plugins I’ve used. They’re both loaded at the end of the document in the footer. I have full control of the theme (from scratch), all plugins and I manually control js/wp plugins.

I do still enque jQuery.

So is there still any benefit to enqueuing scripts when I’m doing it this way?

Edit for answer:

  1. I’m controlling the JS of *JS* plugins, like velocity, retina.js, etc.
  2. If you’re editing my code, the css is in the single css file, the js is in a single js file, if it’s a (js)plugin, put it in plugins.js.
  3. The themes are created in such that clients don’t add plugins, limited wp-admin.
  4. Dependencies are irrelevant, the only one is jQuery, which is the only one I load with WP.
  5. No need for versioning, or haven’t had to so far.
  6. With minimal, minified JS, it’s better to load all in one gzipped file than multiple http requests.

If I didn’t use a plugins.js file for all the js plugins, then there would be multiple http requests done by wp, or if I used a caching plugin I’d have to piss about refreshing the cache while editing. I’m not saying you’re wrong, I’m just saying none of those reasons really help. As far as I can tell…

2 Answers
2

Why are you manually controlling Plugin’s javascript files?

1) It’s never bad practice to do things like they are supposed to be. That way, when you need to, it’s not a mountain to climb.

2) If you’re sick and I’m hired to look at your code, I expect javascripts and css to be loaded the proper way. Pasting them in the will only cost me more time and confusion.
3) If you ever plan to use a plugin (or your client installs a plugin) or such which loads the same javascript as your theme does, you’re in for a conflict.
4) wp_enqueue_script gives you control over dependencies and can put the javascript code in your order in the header or at the bottom of the page. More control = always better! (even if you don’t use it, you have the option to expand).
5) You can use version numbering.
6) You can load scripts only on the pages that need that code.

You’re basically just giving yourself more work…..

I think the question should always be “is it justified not to use it?” instead of “is it justified to use it?”.

EDIT FOR UPDATED QUESTION:

I think you kind of answered your own question here. When you don’t use ANY advantage that wp_enqueue_script() gives you, it will not give any advantage. (The logic :P).

I would still load it through wp_enqueue_script() if I were you though. You said you only have 1 .css file & 2 .js files. If I understand you correctly, you manually manage and compile all your javascript & css to these few files. New javascript & css will always still be compiled to those files. In that case you can just as easily type the needed wp_enqueue_script() once and you will never have to look at it again.

It won’t give many (important) advantages, but still:

1) You will then be more according to standards, which will still be less confusing.

2) If you ever want to, you can instruct wordpress to drop the specified .css or .js file on a specific page or something similair. (I once made a website where i had no need for any javascript on that particular page, so the scenarios exists).
3) May you ever in the future, for whatever reason need to compile seperate .js files (maybe because you have a very js-heavy page on your website), you can choose on a page basis how and which one you will load.

Like I said before, I think you should look for reasons not to do it according to standards. Not the other way around. So instead of me trying to give answers why you should. Why don’t you give reasons why you shouldn’t?

The only disadvantage I see is that it’s (maybe) easier to just put in the footer instead of having to put it in functions.php.

But if that’s the only disadvantage, like I said, you can just do it once and never have to look at it again. So that’s not a real disadvantage IMHO.

Leave a Comment