DEV Community

Cover image for Creating a Vue Application with CDN setup
Lenildo Luan
Lenildo Luan

Posted on

Creating a Vue Application with CDN setup

Vue.js isn't called "The progressive JavaScript Framework" for nothing. They are called that because you don't need to install a lot of npm packages and recreate your entire project in a new framework. If you have an existing website and need to add some interactive features to it, just add the Vue.js by script tag and use it in your page. How to do that? Let's see in this post.


Using Vue from a CDN (Content Delivery Network) means that instead of downloading and hosting the Vue.js library on your server, you include it in your web project by linking to a version hosted on a CDN. This technique offers several advantages for vanilla web projects that want to add more complex user interfaces or modernize their code. Furthermore, another reason for using this method:

  • Speed and Performance: CDNs are optimized for delivering content efficiently. They often have servers all over the world, ensuring that your users download Vue.js from a location close to them, reducing load times.

  • Ease of Use: It's straightforward to include Vue in your project. You just need to add a <script> tag in your HTML file that points to the Vue.js CDN link.

  • No Installation Required: There's no need to install Vue using npm or yarn, which can be beneficial for small projects or for learning purposes.

However, there are also downsides to using a CDN:

  • Reliance on external service: Your project's functionality might be compromised if the CDN goes down or has issues.

  • Limited control: You have less control over the version of Vue being used, unless you specify a particular version in the CDN link.

  • Not Ideal for larger projects: It's often better to install Vue locally to have more control over the environment and to use Vue's powerful development tools.

To use Vue from a CDN, just add a script tag with they src pointed to URL where is located the Vue.js file:

  <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>

  <div id="app">{{ message }}</div>

  <script>
    const { createApp, ref } = Vue

    createApp({
      setup() {
        const message = ref('Hello vue!')
        return {
          message
        }
      }
    }).mount('#app')
  </script>
Enter fullscreen mode Exit fullscreen mode

The example above adds Vue to the project and creates a hello world app to validate if the framework as imported successfully.

Concluding

In conclusion, using Vue.js via a CDN is a convenient and efficient way to modernize an existing web project or to add interactive features without the complexities of a full framework installation. By adding just a few lines of code, you can significantly enhance your web application, making Vue.js a versatile and accessible tool for web developers of all skill levels.

In the next post, we'll explore the Hello World example and understand every aspect of this coding. See you there!

Tiugo image

Modular, Fast, and Built for Developers

CKEditor 5 gives you full control over your editing experience. A modular architecture means you get high performance, fewer re-renders and a setup that scales with your needs.

Start now

Top comments (0)

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

👋 Kindness is contagious

Explore this insightful post in the vibrant DEV Community. Developers from all walks of life are invited to contribute and elevate our shared know-how.

A simple "thank you" could lift spirits—leave your kudos in the comments!

On DEV, passing on wisdom paves our way and unites us. Enjoyed this piece? A brief note of thanks to the writer goes a long way.

Okay