

GitHub - MarketingPipeline/File-Loader.js: Easily load scripts and style-sheets...
source link: https://github.com/MarketingPipeline/File-Loader.js
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

File-Loader.js
The easiest way to load scripts & stylesheets to your HTML page
Show your support!
Example and usage
How to use File Loader:
You can load a script / stylesheet or MULTIPLE scripts & stylesheets like so -
<script type="module">
import {FileLoader} from 'https://cdn.jsdelivr.net/gh/MarketingPipeline/[email protected]/dist/file-loader.min.js';
async function example_usage(){
try{
let files_to_load = await FileLoader([{url: "https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/js/bootstrap.min.js", file_type:"js"},
{url: "https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css", file_type:"css"}])
} catch (error){
console.log(error)
}
}
example_usage()
</script>
How to use File Loader to load files from a template:
You can store your file(s) to load as a json
file and fetch them via a URL. Example below -
<script type="module">
import {FileLoader} from 'https://cdn.jsdelivr.net/gh/MarketingPipeline/[email protected]/dist/file-loader.min.js';
async function load_files_from_template(){
try{
let files_to_load = await FileLoader("https://your_project_URL_here.com/files_to_load.json")
console.log(files_to_load)
} catch (error){
console.log(error)
}
}
load_files_from_template()
</script>
Append to head
By default scripts & stylesheets will be appended to the body
You can where the file gets appended to by adding a json key named append_to_head
- like so
FileLoader([{url: "your_script_here.js", file_type:"js", append_to_head:true}])
Apply attributes
You can apply attributes like defer, async, type & etc
to your scripts & stylesheets like so -
FileLoader([{url: "your_defer_script.js", file_type:"js", attributes: {defer: '', type:"text/javascript", your_custom_attribute:"here"}}])
Contributing
Want to improve this? Create a pull request with detailed changes / improvements! If approved you will be added to the list of contributors of this awesome project!
See also the list of contributors who participate in this project.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Recommend
-
12
Masonry Layout Level 3 of the CSS Grid Layout specification includes a masonry value for
-
5
Using CSS animations CSS animations make it possible to animate transitions from one CSS style configuration to another. Animations consist of two components, a style describing the CSS animation and a set of k...
-
15
ClosedXML.SimpleSheets A library to easily generate Excel sheets from data in F#. Built on top of ClosedXML Install dotnet add package ClosedXML.SimpleSheet...
-
7
Sending Emails with Google Sheets & Scripts Google Sheets and Google Scripts have been a powerful combo for me...
-
5
关于样式编译因为webpack编译的思想是万无皆可JS,意旨所有web项目关联的资源文件,都可以通过js关联起来。然而又由于图片,样式这些本来和js八竿子打不到一起的,所以就有了各种loader来解决他们的关联性问题;说到webpack的样式编译,总有几...
-
8
大家伙都清楚在使用webpack构建前端项目时都会使用到sass-loader、less-loader、postcss-loader、css-loader、style-loader,但这些loader在其中起到什么作用呢?本篇主要阐述css-loader与style-loa...
-
8
By:
-
23
DSU Sideloader lets you easily boot any custom GSI via Android DSU LoaderLast week, Google released the first Developer Preview build of
-
7
style-loader与iframe的问题 通常情况下其实遇不到style-loader与iframe纠缠的情况,不过由于自己所做项目的特殊性,所以不得不经常与iframe打些交道,并且往往遇到问题能参考的资料也非常有限。
-
11
IPTV-Parser.js
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK