开发者

How does jQuery.ajax({url:'foo.js', dataType:'script', async:false}) differ from document.write?

开发者 https://www.devze.com 2023-03-08 10:42 出处:网络
I was hoping to use $.ajax({url:\'foo.js\', async:false, dataType:\'script\'}) to block content display until foo.js had loaded.The assumption was that synchronous script loading is roughly equivalent

I was hoping to use $.ajax({url:'foo.js', async:false, dataType:'script'}) to block content display until foo.js had loaded. The assumption was that synchronous script loading is roughly equivalent to document.write. I'm guessing that's incorrect since I still get FOUC.

While I can solve the immediate issue by hiding the element and showing it on script load, I'm curious how the synchronous $.ajax call differs from document.w开发者_StackOverflow社区rite. If you happen to know a way to get content blocking behavior from jQuery, that would be interesting also.

Thanks!

Adam


You could define a variable/construct in foo.js, and wait for its definition.

The .load() function can be used to wait on a certain element's load: http://api.jquery.com/load/

0

精彩评论

暂无评论...
验证码 换一张
取 消