F
F
frontendo2019-01-26 08:12:48
JavaScript
frontendo, 2019-01-26 08:12:48

Is it possible to somehow load modules by url?

I would like to have such a construction
import(' https://site.com/module.js ').then(function(module) {
// ...
})

Answer the question

In order to leave comments, you need to log in

3 answer(s)
F
frontendo, 2019-01-27
@frontendo

the solution was to use https://www.npmjs.com/package/little-loader

O
Oleg, 2019-01-26
@lolzqq

Read the article about document.createElement(tag)
Create a tag <script>, the browser loads the script itself, register a variable at the end of the body of the loaded script, and on the page itself, where you load it, periodically ask for the presence of this variable, if it is registered - it means the script has loaded and then do the following what you wanted.

V
Vitsliputsli, 2019-01-26
@Vitsliputsli

What exactly is the problem? Webpack has import/export, and it also has require.
The syntax is perhaps different, something like (better check in the documentation):
https://site.com/module.js: export function module module() { ... }
And loading:
import {module} from " https: //site.com/module.js "

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question