Gathering detailed insights and metrics for react-async-script-dyn-loader
Gathering detailed insights and metrics for react-async-script-dyn-loader
npm install react-async-script-dyn-loader
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
7,325
Last Day
8
Last Week
9
Last Month
25
Last Year
516
31 Commits
1 Forks
1 Watching
2 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
0.2.4
Package Id
react-async-script-dyn-loader@0.2.4
Unpacked Size
23.73 kB
Size
7.70 kB
File Count
12
NPM Version
6.1.0
Node Version
8.9.4
Cumulative downloads
Total Downloads
Last day
0%
8
Compared to previous day
Last week
-30.8%
9
Compared to previous week
Last month
-28.6%
25
Compared to previous month
Last year
-55.6%
516
Compared to previous year
1
1
24
A decorator for script lazy loading on react component.
Some component may depend on other vendors which you may not want to load them until you really need them. So here it is, use High Order Component to decorate your component and it will handle lazy loading for you, it support parallel and sequential loading.
1npm install --save react-async-script-loader
1scriptLoader(...scriptSrc)([WrappedComponent])
scriptSrc
can be a string of source or an array of source. scriptSrc
will be loaded sequentially, but array of source will be loaded parallelly. It also cache the loaded script to avoid duplicated loading. More lively description see use case below.
Decorated component will receive following properties:
Name | Type | Description |
---|---|---|
isScriptLoaded | Boolean | Represent scripts loading process is over or not, maybe part of scripts load failed. |
isScriptLoadSucceed | Boolean | Represent all scripts load successfully or not. |
onScriptLoaded | Function | Triggered when all scripts load successfully. |
You can use it to decorate your component.
1import React, { Component } from 'react' 2import scriptLoader from 'react-async-script-loader' 3 4class Editor extends Component { 5 ... 6 7 componentWillReceiveProps ({ isScriptLoaded, isScriptLoadSucceed }) { 8 if (isScriptLoaded && !this.props.isScriptLoaded) { // load finished 9 if (isScriptLoadSucceed) { 10 this.initEditor() 11 } 12 else this.props.onError() 13 } 14 } 15 16 componentDidMount () { 17 const { isScriptLoaded, isScriptLoadSucceed } = this.props 18 if (isScriptLoaded && isScriptLoadSucceed) { 19 this.initEditor() 20 } 21 } 22 23 ... 24} 25 26export default scriptLoader( 27 [ 28 'https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js', 29 'https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.5/marked.min.js' 30 ], 31 '/assets/bootstrap-markdown.js' 32)(Editor)
The example above means that the jquery
and marked
will be loading parallelly, and after loaded these 2 vendors, load bootstrap-markdown
sequentially.
It is possible that some script will be failed to load. ScriptLoader will cache the script that load successfully and will remove the script node which fail to load before.
Currently, if you try to reload scripts, you have to remount your component.
And it's cooler if you use decorator syntax. (ES7)
1@scriptLoader( 2 [ 3 'https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js', 4 'https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.5/marked.min.js' 5 ], 6 '/assets/bootstrap-markdown.js' 7) 8class Editor extends Component { 9 10}
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
no SAST tool detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
90 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More