Why does a React build need to be served? Why can't I just open it in the browser?

Viewed 41

Apologies for somewhat of a basic question, but I haven't been able to find the technical reason anywhere I've looked.

Basically, if I do npm run build I get a static html file and a bunch of css and javascript files in the build folder. I would think that I should then be able to open up that index.html file in the browser and have it work, just as would be the case for some static HTML built without React.

So, my question is: what is it that react is relying on that requires to be served up with a static file server like serve or webpack dev server?

1 Answers

It uses Ajax internally. The Same Origin Policy prevents it reading file: scheme URLs in most browsers.

Related