简体   繁体   中英

What are the implications of using the script async attribute?

I am working on ASP.NET MVC 4 HTML5 project. Recently we have added marketing scripts that are taking up to 10 seconds to load. When I went to look for what's going on I have found that none of scripts were loaded asynchronously.

My initial response was to add async on each and every third-party script that we have, but then I thought of what implications would be. I am not talking about our local scripts that have to be loaded in a specific order.

The only thing I can think of is if the user manages to complete the form and get to the next page before the script loads third-party scripts would not get marketing information for that page (which I am OK with).

What are other things that could happen when switching scripts to be async that can ruin my day?

UPDATE: Since for some it's not obvious what I am looking for here's one example .

One of the side effects is you will not be able to use document.write which is described in more detail here .

Another is if there is a sequence in which scripts from third parties are expected to fire order might come anything so will behaviors. This can be remedied by separating loading and firing of scripts, but it might be impossible to do as it depends on competent third-party developers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM