playgrdstar
creative coding space
1 min readJul 24, 2018

--

When your html page refuses to load an external file

Not all static html pages can just be loaded just by opening it in a browser. This is something that trips up a beginner very often.

If a static webpage is self-contained, and does not rely on any other files, or the files it relies on can be loaded over the interwebs it should render with no issues.

But if the static webpage relies on an external file sitting on your computer, for example -

<script type="text/javascript" src="./js/index.js"></script>

or we require data contained in an external file (e.g. a csv or text file) to generate a visualisation, for example -

d3.csv(‘data.csv’, function(d){…

then the page won’t load.

Solving this is really simple. You just need to have a way to boot-up a server on your computer. Open up a terminal at the folder where the files reside, and run the server. You will then be able to go to something like 0.0.0.0:8000 (the address will usually be indicated on your terminal) on your browser and run the html file from there. If you have Python installed it’s a simple matter of running either of the two command below -

Python 3

`python -m http.server`

Python 2

python -m SimpleHTTPServer

playgrd.com

--

--

playgrdstar
creative coding space

ming // gary ang // illustration, coding, writing // portfolio >> playgrd.com | writings >> quaintitative.com