Can you explain the difference between CDN and ESM builds in vue.js?

According to the Vue.js documentation, there are differences in syntax depending on whether you are using the CDN or ESM build of Vue.js. What is the significance of having two different builds and how does it result in a difference in usage syntax?

Information from vue.js documentation:

// CDN build of Vue
const { KeepAlive, Teleport, Transition, TransitionGroup } = Vue

// ESM build of Vue
import { KeepAlive, Teleport, Transition, TransitionGroup } from 'vue'

Answer №1

Importing a CDN is essentially adding the script in a traditional manner, like this:

<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5f292a3a1f6d7169716e6d">[email protected]</a>/dist/vue.js"></script>

The ESM build refers to an ES module that is installed in your project and utilized with a bundler (such as Webpack) by importing it like this:

import coolMethod from 'nice-package'

While both methods provide similar functionalities, the CDN approach may have limitations in terms of customization and optimization. Opt for the ESM option if possible.

This informative article discusses CJS, AMD, UMD, and ESM variations: https://dev.to/iggredible/what-the-heck-are-cjs-amd-umd-and-esm-ikm
Regarding CDNs, they are typically considered the fallback solution and not the most optimal choice. For further details, it is advisable to conduct additional research outside of Stack Overflow's guidelines.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating dynamic <a> tags using JavaScript

My current view includes a div tag with 2 links - one for displaying the page in English and another for Arabic. I want to modify it so that if the page is already in English, only the Arabic <a> tag will show, and vice versa if the page is in Arabic ...

Implementing Batch File Uploads using Typescript

Is there a way to upload multiple files in TypeScript without using React or Angular, but by utilizing an interface and getter and setter in a class? So far I have this for single file upload: <input name="myfile" type="file" multi ...

How can Angular JS detect the names of the CSS files being used in an HTML page?

I am in the process of developing a brand new widget where we are incorporating a unique feature that displays the number of CSS files included within an HTML page. Our team requires the count and names of all CSS files utilized on the webpage. While I a ...

The process of compressing videos and image files is done automatically in a React production build

I've recently finished building a react application and have deployed it with the production build. yarn run build serve -S build While I know it compresses the .js and .scss files, creating a build folder to serve from, I'm wondering if it also ...

At which point does a computed property get activated in VueJS?

Suppose I have a form with an <input> element and '' within it. My goal is to create a computed property that will keep track of the <input> field, and whenever the user clears everything from this <input>, the computed property ...

Turn off all animations for a specific div or HTML page

Whenever I add an item to a div, there's this strange flashing animation happening. It's like a blink or flash that updates the div with new data. I'm not entirely sure if it's a jQuery animation or not. Is there any way to disable all ...

What methods can be used to ensure that the variable $ can serve as both an object and a function?

One interesting feature of jQuery is how the variable $ can function as both an object and a function. // For example, you can access object properties like $.fn; // or $.isReady; // You can also call the function $ like this $(); So, how can we make the ...

Transferring Data in Vue.js Components through Props

I've encountered an issue while trying to pass a prop from the main Vue instance to a component. While one of the props is being successfully passed, the second one seems to be causing some trouble. Main Instance var app7 = new Vue({ el: &apos ...

Arrange objects in an array based on certain criteria using JavaScript in a dynamic

I have an array containing various items that need to be sorted according to specific rules. The goal is to group all values with "rules" together, and ensure that "ELIG_DATABASE" is grouped with "ELIG_SERVICE." const items =[{"name":"ELIG_ ...

What is the best way to prevent a folder from being included in the next js build process while still allowing

I am faced with a challenge involving a collection of JSON files in a folder. I need to prevent this folder from being included in the build process as it would inflate the size of the build. However, I still require access to the data stored in these file ...

When utilizing jQuery lightbox to pull data from a database using PHP/Ajax, it may require a double click the

Encountering a strange issue where I must click on specific buttons with unique IDs. These IDs are then sent through Ajax to a PHP script, which searches for corresponding entries in the database. The retrieved data is then displayed in a jQuery lightbox. ...

Having trouble resolving a component from a component library while utilizing NPM link

My React application is set up with Create React App and a separate component library. I'm currently experimenting with using 'npm link' to test changes in the component library directly on my local machine. To achieve this, I first run &ap ...

Lumen - Issue with CORS: request successfully completed despite missing 'allow origin' header

I am facing an issue with my Lumen-VueJs application When I make a request, the status is 200 and I receive the expected response, but the request appears to be blocked on the 'network' (see screen below): In my app, I have a CorsMiddleware con ...

Refreshing knockout viewModel with the mapping plugin is a great way to update the data

I'm attempting to refresh a small widget using knockout and the mapping plugin. Below is the code I have written so far: var AppViewModel = function (data, total, qty) { var self = this; self.Products = ko.mapping.fromJS(data, {}, this); ...

Tips for successfully including a forward slash in a URL query string

My query involves passing a URL in the following format: URL = canada/ontario/shop6 However, when I access this parameter from the query string, it only displays "canada" and discards the rest of the data after the first forward slash. Is there a way to ...

Is it possible to identify if an array is a polygon or multipolygon by examining its GeoJson data?

Recently, I came across an example illustrating a simple polygon. However, I wanted to display countries with complex polygons (multipolygons for some countries). Let me demonstrate the process: Example: "type": "Feature", "properties": { "Na ...

Ways to retrieve files that are not located in the public directory in Next.js

I'm currently working on a project using Next.js and storing files in the root directory under /uploads/qr/myimage.png. How can I access this file within the project? I attempted to create a route /api/getImg/route.js dedicated to serving image files, ...

Does anyone have any insight on why I can't seem to remove an item from my list of tasks?

Having trouble with my React todo list. After submitting, the list item looks fine. I expect to be able to delete it by clicking on the item, but nothing happens. When I try to add another item, the page refreshes and all items are removed. The console ...

The ID Token could not be verified due to an invalid jwt.split function

I'm currently working on validating a Google ID Token on my Node.js server. Unfortunately, I've encountered the following error: The ID Token cannot be verified: jwt.split is not a function For reference, here is the link to the code that I am ...

Utilizing Angular to efficiently download and showcase PDF files

Presently utilizing https://github.com/stranger82/angular-utf8-base64 as well as https://github.com/eligrey/FileSaver.js/ for the purpose of decoding a base64 encoded PDF file that I am fetching from a rest API. It successfully decodes and downloads, ...