0

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Matas Vaitkevicius
  • 58,075
  • 31
  • 238
  • 265
  • 3
    Related, if not duplicate: http://stackoverflow.com/questions/10808109/script-tag-async-defer – Tomalak Jan 30 '15 at 10:03
  • @Tomalak could you point me where they are talking about implications please. – Matas Vaitkevicius Jan 30 '15 at 10:05
  • @Tomalak Or are you referring to these? 'Async is more useful when you really don't care when the script loads..', 'Usually the jQuery library is not a good candidate for async..' this isn't implication, just explanation how it works which I have already described in question **'I am not talking about our local scripts that have to be loaded in specific order.'** – Matas Vaitkevicius Jan 30 '15 at 10:12
  • Well since `async` purely affects the *loading* behavior of a script (and not its runtime behavior), I would not expect any ill-effects for standalone scripts that no other scripts depend on. – Tomalak Jan 30 '15 at 13:14

1 Answers1

0

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Matas Vaitkevicius
  • 58,075
  • 31
  • 238
  • 265