1

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/

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much. Nagyon szépen köszönjük. Console should notice typos i guess :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.