K
K
kalnin_yuri2021-11-11 01:49:23
Frontend
kalnin_yuri, 2021-11-11 01:49:23

How to force VUE to load dynamic components from CDN?

anyone know if it's possible to force vue to load dynamic components via cdn in production?

this is how the vue script file itself
618c4c255f5e1448295943.png

is loaded, this is how the dynamic component is loaded
618c4c14479e5910439010.png

directly from the server.

the component itself

Vue.component('page-projects', (resolve) => {

        return require.ensure([], (require) => {

            return resolve(require('./components/pages/projects/index.vue'));

        }, "components/pages/projects/index");
    });

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2021-11-11
@Aetae

Vueuses webpack, but webpackuses specific paths for requests that you specify when building.

Head- on solution:
a special build for cdn, where the parameter publicPatchpoints to the corresponding site.
The solution is tricky:webpack it allows you to change the public path dynamically by assigning it to the __webpack_public_path__. All that remains is to get the path to the script at the start of the application, for example from document.currentScript, select the desired path from it and assign it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question