javascriptcdn

JsBarcode does not work locally, no problems from CDN


I want to use JsBarcode.all.min.js locally (because the intended target will not have an active internet connection) but it does not work after downloading.

When I download and reference as follows:

<script src="JsBarcode.all.min.js"></script>

I get an error when trying to create a barcode:

JsBarcode.all.min.js:2 Uncaught SyntaxError: Invalid regular expression: /^[-_È-Ã]*/: Range out of order in character class (at JsBarcode.all.min.js:2:25056)
    at new RegExp (<anonymous>)
    at o (JsBarcode.all.min.js:2:25056)
    at e.default (JsBarcode.all.min.js:2:25767)
    at new e (JsBarcode.all.min.js:2:24495)
    at v (JsBarcode.all.min.js:2:19469)
    at JsBarcode.all.min.js:2:19402
    at t.value (JsBarcode.all.min.js:2:60628)
    at d.<computed>.d.<computed>.d.<computed> (JsBarcode.all.min.js:2:19268)
    at h (JsBarcode.all.min.js:2:19000)
    at <anonymous>:1:1

when I reference it from the JsDelivr CDN:

<script src="https://cdn.jsdelivr.net/npm/jsbarcode@3.11.6/dist/JsBarcode.all.min.js"></script>

it works fine.

I suspect it has something to do with encoding, but why would wget download something different than the browser? I checked the code in Chrome and when I use the CDN I see differences from when I use a local file.


Solution

  • Content encoding in headers of your server is probably different from the CDN.

    Content-Type: application/javascript; charset=utf-8
    

    Take a look at the charset part of you server's responce.

    In case you're opening a local file the encoding is probably comming from html head tags like:

    <meta charset="UTF-8">
    

    There's probably a way to specify charset for included javascript file too on the script tag.