Kviz Majster
Kviz Majster

Reputation: 108

How to add external .js script to my index.html

In my public/index.html I need to load external .js file which will be used later during deployment. Unfornately that file doesnt load when i npm start, nor when published in build. I dont get any error either. The file config.js is in public directory as well.

Added this to my index.html in tag:

<script type="text/javascript" scr="%PUBLIC_URL%/config.js"></script>

config.js looks like this:

alert(5);
var test=5;

I get no error in console, but it doesnt resolve at all. Nothing happens. (i've tried playing with paths, googling around for hours but no luck. I guess there must be some security setting in react or something that prevents me from loading that script?)

ps: i am tring this which is not working for same reason for me: https://www.cotyhamilton.com/build-once-deploy-anywhere-for-react-applications/

Upvotes: 1

Views: 1061

Answers (1)

Zsolt Meszaros
Zsolt Meszaros

Reputation: 23189

It's not my longest answer. You need to fix the typo, the correct attribute is src not scr on your script tag. If you change it, it will work fine:

<script type="text/javascript" src="%PUBLIC_URL%/config.js"></script>

Upvotes: 1

Related Questions