Load Required JavaScript & CSS Files On Demand – Bring.js

Category: Javascript | February 4, 2022
Author:yunuskkhan
Views Total:72 views
Official Page:Go to website
Last Update:February 4, 2022
License:MIT

Preview:

Load Required JavaScript & CSS Files On Demand – Bring.js

Description:

Bring.js is a JavaScript library that enables you to dynamically load specified JavaScript and/or CSS files on the top or bottom of the webpage when needed.

Similar to lazy loading technology but more flexible.

It is designed to make the web app faster to load and only bring the needed libraries to a specific workplace instead of loading the whole header file that makes the webpage load very slow.

This can be useful to load required JS & Stylesheet on demand to reduce page load time.

How to use it:

1. Import the Bring.js JavaScript library.

<script src="bring.js"></script>

2. Initialize the Bring.js.

var brng = new bring();

3. Define JavaScript and CSS files to be loaded later.

// Stylesheet
brng.addLibrary('mycss','/path/to/styles.min.css','link');
// JavaScript
brng.addLibrary('myjs','/path/to/app.min.js','script');

4. Load the JavaScript and CSS files when needed.

// load the Stylesheet in the head section
brng.bring('mycss','head');
// load the JavaScript at the end of the document
brng.bring('myjs','end');

You Might Be Interested In:


Leave a Reply