ramnathv / htmlwidgets

HTML Widgets for R
http://htmlwidgets.org
Other
792 stars 205 forks source link

Async load JS libraries #339

Open dipterix opened 5 years ago

dipterix commented 5 years ago

It it possible to mark a js library to be async loaded?

Like:

<script async src="script.js"></script>
jcheng5 commented 5 years ago

It is not currently. It'd be straightforward to add (in the htmltools package) but generally it's not that helpful since HTML dependencies are usually depended on by non-async JS logic so it's important that they be loaded completely at load time. What specifically are you doing with your dependency?

dipterix commented 5 years ago

I'm writing a widget type that include libraries with size ~25MB (https://bgrins.github.io/videoconverter.js/). This library is not needed until you use it.

For local machine it's totally fine, but once I put it on websites, it's hell slow. Right now I have to manually go to the source code and change it, but it should be straightforward to add this option in R and I think it almost has no side-effect. We can then also have defer keyword to make JS loading non-blocking for the browsers.