When we are talking about end users’ usage for adding custom CSS, Js files via wp enqueue script Function, it has advantages and disadvantages. It is not that wp enqueue script Function is always great for better Page Speed or practical handling. Basically the PHP echo function can also be used for adding any script at any place – header, footer, body etc. The PHP echo function to the less techie WordPress users become using Plugin like Header and Footer or the Theme’s Function to add scripts.
Why We Should Weigh the Advantages and Disadvantages of wp enqueue script Function?
Previously, we have talked about WP Enqueue Script For WordPress Themes and on topics like to Speed up WordPress With Enqueue Scripts and Rackspace Cloud Files. But, we also talked about the potential practical issues we face on Google Page Speed Test and their various ways to get rid off in the article Eliminate Render-blocking Javascript and CSS WordPress (Reloaded Version) and Defer Parsing of Javascript in WordPress.
Take that, for your custom design; you need to add 5-9 Javascript or jQuery Plugins – they might not be combined. Actually you have lesser control on js served via wp enqueue script Function when compared PHP echo function. You can hardly add to footer. For CSS, the control with wp enqueue script Function is even lesser.
---
So, where we actually should use wp enqueue script Function and where clearly we should avoid it? Here comes a kind of comparison of the methods to practically inject stuffs at front end.
wp enqueue script Function is Actually For the Plugin and Theme Developers
If you add a javascript using this method using WordPress Plugin like Header and Footer or the Theme’s Function to add scripts :
1 2 | <script type='text/javascript' src='// where-is-your-cdn.cdn.com/jquery.js'>execOnReady(function(){});</script> # note execOnReady(function(){}); within <script type =''> and </script> |
It will actually do better than wp enqueue script Function and in more easy way. There are specific advantages of wp enqueue script Function :
- It only load the scripts when needed
- Safely handles the dependencies
- It handles the load order and placement
- It handles the $src properly
- It supports versioning
For example, you want to load a custom Font script for your theme, for example like we described for creating HTML5 CSS3 Custom Social Sharing Buttons For WordPress With Sharrre, wp enqueue script Function might be more efficient and reliable than PHP echo or using frank plugin or theme to inject Javascript / jQuery and CSS, we are actually performing using kind of Plugin like function.
Tagged With advantages of enqueue