Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I load Vue.js from a CDN in production?

I chose Vue.js for a new project because it seems to run natively in the browser, as opposed to something like React that has to be compiled/transpiled via Node. Is there any reason I couldn't just link to a CDN like this in my production code?

<script src="https://unpkg.com/[email protected]"></script>

A co-worker suggested that may be for development only, and that unpkg is simply transpiling on the fly (which doesn't sound good for performance). But other than that it seems to work fine. I could also link to a more robust CDN such as this one, but just want to make sure I'm not violating some sort of best practice by not using a Node build system (e.g. webpack).

like image 354
serverpunk Avatar asked Feb 27 '17 14:02

serverpunk


People also ask

Can we use CDN imports on VueJS?

You can add cdn styles/scripts directly to the ./index. html or ./public/index. html in [email protected].

How do you use VueJS by using CDN?

All you need to do is to copy this tag and link it to your HTML file. Here, you can see that in our HTML file we have linked the CDN by using a script tag, and under that script tag, we wrote Vue code with another script tag. You can write it by creating a separate file and then linking it to the HTML file.

How do I run Vue app in production mode?

If we are using the full build i.e including Vue directly using the script tag without using a build tool, we should make sure we use the minified version (vue. min. js) for production. We can run the bundling command with the actual NODE_ENV environment variable set to "production".

Is Vue production ready?

You can start your new production projects with Vue 3 - the core and subprojects are ready to use.


2 Answers

Is there any reason I couldn't just link to a CDN like this in my production code?

No, there is no reason not to use a CDN in production. It's even a preferred way for serving content in production mode, especially with common packages like jQuery, because most of the people would already have loaded and therefore cached this resource.

A co-worker suggested that may be for development only, and that unpkg is simply transpiling on the fly (which doesn't sound good for performance).

This is absolutely not true - that's why it is a CDN! :) It's a matter of choice, but you have to keep in mind that most of the time you should work with specific version of the library that you are using during development. If you just add the latest version of any code, you are vulnerable to all changes pushed to that repository, and so your clients will start receiving updated code, which you haven't tested yet.

Therefore fix to a specific version that you develop with, open a beer and have a good sleep :)

like image 127
Andrey Popov Avatar answered Oct 06 '22 05:10

Andrey Popov


These maybe help:

<!-- development version -->
<script src="https://unpkg.com/vue"></script>

<!-- production version -->
<script src="https://unpkg.com/vue/dist/vue.min.js"></script>

And it will keep current version of Vue.js automatically.

like image 41
boyal Avatar answered Oct 06 '22 05:10

boyal