Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/grvpanchal/loading-scripts

The repo explain the different way to load script tag containing JavaScript onto you website.
https://github.com/grvpanchal/loading-scripts

Last synced: 10 days ago
JSON representation

The repo explain the different way to load script tag containing JavaScript onto you website.

Awesome Lists containing this project

README

        

# Ways of loading JavaScript via loading scripts tags

## Description
The repo explain the different way to load script tag containing JavaScript onto you website.

## Setup

Install Packages
```sh
npm install
```
Start the server
```sh
npm start
```

Access you server via http://localhost:5000

# Information

This repo demonstrates the 5 ways import JavaScript via `` tag

1. Normal Script Tag
```html
<script>
function createWorld() {
const h2Element = document.createElement('h2');
h2Element.innerHTML = 'Content loaded via script tag';
document.body.appendChild(h2Element);
}

createWorld();

```
2. Script Tag with local Resource file
```html

```
3. Script Tag with External Resource file
```html

```
4. Script Tag that dynamically loads a script file
```html

function loadScriptDynamically(src) {
const scriptElement = document.createElement('script');
scriptElement.src = src;
document.head.appendChild(scriptElement);
}

setTimeout(() => loadScriptDynamically('./assets/js/createDynamicInsertWorld.js'), 3000);

```
5. Script Tag that supports ES6 Module Import
```html

```

I hope I have covered all ways. Address bar way not considered. Please let me know if you guys know additional