
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
@googlicius/load-assets
Advanced tools
Utilities to load assets programatically: javascript, css, images,...
I am a fan of using javascript libraries from their CDN rather than include them in the application bundle. If you are building application with React.js, Angular, or Vue.js, there are many wrapper of libraries you need. But it causes a problem called bi-incompatible
(that's what I call it) when you upgrade your framework to latest version. Some javascript libraries doesn't support npm installation, or you just want to load it as lazy way (when user reach a specific page).
npm install @googlicius/load-assets
Or Yarn
yarn add @googlicius/load-assets
import { loadScript } from '@googlicius/load-assets';
loadScript(
'https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js',
).then(() => {
// Lodash available here.
});
Loads and runs 2 javascript files in parallel.
loadScript(
'https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js',
'https://connect.facebook.net/en_US/sdk.js',
).then(() => {
// Lodash and Facebook SDK available here.
});
Load 2 javascript files in parallel but runs in order, which means the second script depends on the first one.
loadScript([
'https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/prism.min.js',
'https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/plugins/autoloader/prism-autoloader.min.js',
]).then(() => {
// Prism initialized with its autoloader.
});
Often a library is not only have javascript but also with its own css file.
So to load css and js we simple use loadAsset
:
import loadAsset from '@googlicius/load-assets';
loadAsset(
'https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/themes/prism-twilight.min.css',
'https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/prism.min.js',
).then(() => {
// Prism initialized with its styles.
});
Load with custom attributes:
loadScript('https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/prism.min.js', {
'data-manual': 'true',
}).then(() => {
// ...
});
MIT
When you upgradge your framework to higher version, but that version possibly incompatible with some library wrappers in your project, or you want to use the latest version of a library but it possibly haven't supported. For example, Reactstrap currently support Bootstrap 4, so you cannot use Bootstrap 5 at this time.
FAQs
Load assets helper
We found that @googlicius/load-assets demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.