Search code examples
javascriptangulartypescriptcdn

I want to download a script from cdn and use it


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


Solution

  • 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"
            ]
          },