Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading