@malko/l.js 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -1
- package/l.min.js +2 -2
- package/package.json +10 -16
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ or using jsdeliver CDN:
|
|
|
33
33
|
</script>
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
-
> If you're looking for the npm package, you should search for l.js
|
|
36
|
+
> If you're looking for the npm package, you should search for **@malko/l.js**
|
|
37
37
|
> ```npm install @malko/l.js```
|
|
38
38
|
|
|
39
39
|
### loading some scripts in parallel others in order
|
|
@@ -108,6 +108,16 @@ As a default l.js load js scripts with their type attribute set to `text/javascr
|
|
|
108
108
|
</script>
|
|
109
109
|
```
|
|
110
110
|
|
|
111
|
+
### Automatic nonce support
|
|
112
|
+
If the script tag used to load l.js has a nonce attribute, l.js will automatically add this nonce to all script tags it creates. This is useful when using Content Security Policy (CSP) to allow inline scripts, as it allows the dynamically created script tags to be executed without violating the CSP.
|
|
113
|
+
```html
|
|
114
|
+
<script src="l.js" nonce="randomNonceValue">
|
|
115
|
+
ljs.load('myLib.js',function(){ /* your callback here */});
|
|
116
|
+
</script>
|
|
117
|
+
```
|
|
118
|
+
will result in the script tag for myLib.js having the same nonce attribute as the l.js script tag, allowing it to be executed under a CSP that allows scripts with that nonce. This works for both scripts and stylesheets loaded by l.js, as the nonce will be added to all tags created by l.js.
|
|
119
|
+
|
|
120
|
+
|
|
111
121
|
this piece of code is dual licensed under MIT / GPL
|
|
112
122
|
Hope this help, code review, suggestions, bug reports are welcome and appreciated.
|
|
113
123
|
|
package/l.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
//https://github.com/malko/l.js v0.2.
|
|
2
|
-
|
|
1
|
+
//https://github.com/malko/l.js v0.2.3 MIT license ©Jonathan Gotti
|
|
2
|
+
((e,l)=>{function a(e,n){return e instanceof(n||Array)}function u(e,n,r){var t,o=c.createElement(e);for(t in(e=v&&(v.nonce||v[p]&&v[p]("nonce")))&&o.setAttribute("nonce",e),r&&(o[s]?o[f]=function(){"loaded"!==o[s]&&"complete"!==o[s]||(o[f]=null,r())}:o.onload=r),n)n[t]&&(o[t]=n[t]);h.appendChild(o)}var c=document,n="getElementsByTagName",i="length",s="readyState",f="onreadystatechange",d="script",p="getAttribute",h=c[n]("head")[0]||c.documentElement,m={},r=c[n](d),v=r[r[i]-1],t=v.innerHTML.replace(/^\s+|\s+$/g,"");if(!e.ljs){var o=v.src.match(/checkLoaded/)?1:0,y=function(e){var o={};return o.u=e.replace(/(^module:)|#(=)?([^#]*)?/g,function(e,n,r,t){return o[n?"m":r?"f":"i"]=!!n||t,""}),o},g={},j=[],A={aliases:m,loadjs:function(n,r){function t(e){for(var n=0,r=j.length;n<r;n++)j[n](e)}var e,o,a,c=y(n),i=c.m?"module":"text/javascript";return!0===g[n=c.u]?r&&r():g[n]!==l?r&&(g[n]=(e=g[n],o=r,function(){e&&e(),o&&o()})):(g[n]=(a=r,function(){g[n]=!0,a&&a()}),r=function(){g[n]()},u(d,{type:i,src:n,id:c.i,onerror:function(e){t(n);e=e.currentTarget;e.parentNode.removeChild(e),u(d,{type:i,src:c.f,id:c.i,onerror:function(){t(c.f)}},r)}},r)),A},loadcss:function(e,n){var r=y(e);return e=r.u,g[e]||u("link",{type:"text/css",rel:"stylesheet",href:e,id:r.i}),g[e]=!0,n&&n(),A},load:function(){var e=arguments,n=e[i];return 1===n&&a(e[0],Function)?e[0]():((e,n,r)=>{var t;if(m&&m[n])return t=m[n].slice(0),a(t)||(t=[t]),r&&t.push(r),e.load.apply(e,t);if(a(n)){for(var o=n[i];o--;)e.load(n[o]);return r&&n.push(r),e.load.apply(e,n)}n.match(/\.css\b/)?e.loadcss(n,r):e.loadjs(n,r)})(A,e[0],n<=1?l:function(){A.load.apply(A,[].slice.call(e,1))}),A},addAliases:function(e){for(var n in e)m[n]=a(e[n])?e[n].slice(0):e[n];return A},onError:function(e){return j.push(e),A}};if(o){for(var E,T,b=0,k=r[i];b<k;b++)(T=r[b][p]("src"))&&(g[T.replace(/#.*$/,"")]=!0);for(b=0,k=(E=c[n]("link"))[i];b<k;b++)"stylesheet"!==E[b].rel&&"text/css"!==E[b].type||(g[E[b][p]("href").replace(/#.*$/,"")]=!0)}e.ljs=A}v.src&&t&&u(d,{innerHTML:t})})(window);
|
package/package.json
CHANGED
|
@@ -1,28 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@malko/l.js",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "another simple/tiny javascript/css loader",
|
|
5
5
|
"files": [
|
|
6
6
|
"l.min.js"
|
|
7
7
|
],
|
|
8
8
|
"main": "l.min.js",
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"js",
|
|
14
|
-
"load",
|
|
15
|
-
"async",
|
|
16
|
-
"dynamic import",
|
|
17
|
-
"import",
|
|
18
|
-
"require"
|
|
19
|
-
],
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "echo \"//https://github.com/malko/l.js v$npm_package_version MIT license ©Jonathan Gotti\" > l.min.js && uglifyjs l.js -m -c >> l.min.js && cat l.min.js | gzip > l.min.js.gz && ls -lh"
|
|
11
|
+
},
|
|
12
|
+
"keywords": ["loader", "script", "css", "js", "load", "async", "dynamic import", "import", "require"],
|
|
20
13
|
"author": "Jonathan Gotti <jgotti at jgotti dot org>",
|
|
14
|
+
"contributors": [
|
|
15
|
+
"malko <jgotti at jgotti dot org>",
|
|
16
|
+
"ivanrey <ivan.rey@inpltda.com>"
|
|
17
|
+
],
|
|
21
18
|
"license": "MIT",
|
|
22
19
|
"devDependencies": {
|
|
23
20
|
"uglify-js": "^3.17.4"
|
|
24
|
-
},
|
|
25
|
-
"scripts": {
|
|
26
|
-
"build": "echo \"//https://github.com/malko/l.js v$npm_package_version MIT license ©Jonathan Gotti\" > l.min.js && uglifyjs l.js -m -c >> l.min.js && cat l.min.js | gzip > l.min.js.gz && ls -lh"
|
|
27
21
|
}
|
|
28
|
-
}
|
|
22
|
+
}
|