12

It is correct to enqueue external scripts with that function? It works but doesn't it slow down opening the site?

wp_register_script( 'google-maps', 'http://maps.googleapis.com/maps/api/js?sensor=true', null, null, true );
wp_register_script( 'jsapi', 'https://www.google.com/jsapi', null, null, true );
wp_register_script( 'bootstrap', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js', null, null, true );
wp_register_script( 'unveil', get_template_directory_uri() . '/new-js/jquery.unveil.min.js', null, null, true );

1 Answer 1

18

No, it doesn't slow the site (at least not enough to make it a reason for not using it). This is the correct way to enqueue any type of script in WordPress. All this function does is add the proper <link> tags (with dependencies) to your HTML <head>.

However, for some reason, you haven't included dependencies in your code. For example, Bootstrap requires jQuery, so you should include it in your function:

wp_enqueue_script( 'bootstrap', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js', array('jquery'), '3.3.5', true );

As shown above, you should also consider using wp_enqueue_script() instead of wp_register_script(), since it will save you a step.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for fast answer. I asked because I have a problem when external scripts slows down the whole page (block other scripts). I have problem with facebook, maps and bootstrap. Is there simple solution for it?

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.