I want to download a script from cdn and use it

好久不见. 提交于 2019-12-11 19:08:00

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!