Is it OK combined wp-include js, jquery, css? [closed]

TL;DR

Yes, your performance will get better, and no, the security as far as WordPress is concerned is not a problem, and apart form general cache-related problems (realtime information etc.) there won’t be any major negative sideeffect.

but…

To give a WordPress specific answer here, I assume that your site and your server-setup meet your security standards already. If they don’t, please refer to Webmasters to get some information about your general setup.

The WordPress specific part

Well, not directly WordPress, it is mainly the W3TC Plugin.

Functionality of the site

If all your scripts/plugins/functions use the right way of enqueueing the CSS and JS in WordPress, you should be safe in general.

With a combination of Javascript-Files into one big combined minified (yeah, it can get really big) you face a few difficulties that you have to master.

The First one would be kind of obvious, but very important – always check your site functionality after trying something new in W3TC (In fact, always check it anyway 😉 ). The thing is, it could happen that you combine your JS files, and you check out your site. Everything works, no JS error. Then you check out your site (not logged in), same result, and you are happy with yourself for getting a higher PageSpeedResult. However, the next user that visits the site finds it being broken. This is because the cache is usually not prebuilt, but after the first not logged-in user visits the site.

Your check routine for combining JS and CSS with W3TC should contain at least these three steps (and yeah, on different browsers, but you get the idea):

  • First check – logged in
  • Second check – logged out
  • Second second check – logged out

Performance of the site

Well, after you managed to finally get the files in the right order and you are confident everything works, you run your performance tests again. This is why you wanted to combine your JS in the first place, isn’t it? 😉

You will find out that you get better results for the number of requests, but you get worse results for the amount of JS and CSS loaded in the <head> or above the fold.

Now comes the second step

This one is going to take a LOT of time, as it is the manual combination of your different JS and CSS files.

As great as W3TC is, it offers you the possibility of defining which script should be combined and loaded at which part of the site. This sounds like the perfect scenario – load all the basic stuff that is necessary in the head, and the rest after your site has rendered.

The problem lies in the fact that not all plugins use the best practices for enqueueing scripts and styles with wp_enqueue_script() and wp_enqueue_style(), and the functionality of a lot of those scripts greatly depends on the position of ther inclusion.

For example, a popular Fancybox Plugin also outputs a part of it’s script inline. With moving the JS Files to the <footer> or combining them in your way can break your whole jQuery-magic in one instance.

Adding new functionality/Plugins

Yeah, you guessed right, and I hate to break this to you – you will have to do the same routine every time you add new Plugins or new functionality to your site. So be sure everything works as expected before putting hours of optimizing into your project before it’s finished.

Mobile concerns

As @rarst pointed out, having huge JS and CSS files can be problematic with mobile devices. Keep that in mind – but this is not the issue concerning your caching, but your site in general.

The WordPress performance itself WILL get better

As W3TC creates files that are delivered instead of dynamically generating them, your site will gain speed and reduce the number of requests. However, this only applies for requests after your cache is built.

What’s next

Unfortunatley, there is no generic solution to how you should deal with this issue. I hope you know what to look out for, and how to learn which plugins you can use and trust there.

Have fun experimenting with this stuff! You may need to alter a few scripts to get them into the right WordPress way, but that’s part of the fun. And the frustration.

And, once again, be sure to check everything multiple times. You reduce the complex functions of various systems (starting from PHP on the Webserver, including your Database, WordPress itself and all your customization and content) to static files.

That’s a really big job, but if you did everything right in the first place, everything should be fine afterwars!