Patrik Krehák
Patrik Krehák

Reputation: 2683

google.load breaks a whole website with jQuery already loaded

When I use google.load in the script, my whole website just disappear. Here is jsFiddle: https://jsfiddle.net/0rc5zL6g/

I'm loading jQuery and then Google's JSAPI. Even with small code like this

$(function() {
    google.load('language', '1');
});

It hides everything. Just try to uncomment that line in the demo and you will see it working. Also no error in the console.

I use much more scripts and jQuery plugins (they require already loaded jQuery, that's why I don't use google.load('jquery', '2.2.4');), but this one will always break the whole website.

I also tried to remove google.load from script. Website works like a charm and when I type it in the console, whole website disappear. Why?

Upvotes: 0

Views: 17

Answers (1)

SLaks
SLaks

Reputation: 887509

google.load() uses document.write() (so that it can load JS immediately so later code doesn't need a callback), so it can only be called synchronously while the document is still rendering.

You can only call that directly in a <script> tag, not when the page loads.

Upvotes: 1

Related Questions