问题
I wanted to download a script and use it instead of using cdn
The cdn links are
<script src="https://cdn.jsdelivr.net/npm/es6-object-assign@1.1.0/dist/object-assign-auto.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/text-encoding@0.6.4/lib/encoding.min.js"></script>
Instead I downloaded and tried to use
<script src="./js/encoding.js"></script>
<script src="./js/object-assign-auto.js"></script>
But it doesnt work it shows
NOT FOUND - The server has not found anything matching the requested URI (Uniform Resource Identifier).
I think I am not using the downloaded files in the right way. suggestions please, thank you
回答1:
Add thr scripts to the angular.json
file, in the scripts
sections.
Paths starts at the root of your folder, so it should be js/encoding.js
:
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
...
"assets": [...],
"styles": [...],
"scripts": [
"js/encoding.js"
]
},
回答2:
Probably you don't have the scripts in the right place or the relative path "./js" is not the correct.
回答3:
Since you have tagged angular
in your post, you must not include scripts inside the template html. You could include them in the index.html to load them directly from cdn or download and include them inside the scripts
array of angular-cli.json
If you are not using angular, the problem could be an incorrect filename
, incorrect folder
or even wrong relative
path.
来源:https://stackoverflow.com/questions/54551487/i-want-to-download-a-script-from-cdn-and-use-it