07 June 2018

How to start a local web server to view HTML files

If you’re viewing files from your local computer in a web browser, their URL will appear with a "file:///" prefix instead of the usual "https://" that you might normally see.

Sometimes browsers give different privileges and treatment to files if they’re local or on a web server. If you need to test a local file out as if it were on a web server.

You can set up a local testing server by following the instructions in these Mozilla docs.

The short version of that is:

  1. open up the terminal or command prompt
  2. navigate to the directory where the files live
  3. run a local python server by running:

    python3 -m http.server 1234

  4. Go to http://localhost:1234/ in your browser and navigate to or type into the address bar the file you’re trying to open

If you run into issues, the Mozilla reference is more comprehensive and should sort things out.


Did you find this helpful or fun? Please donate!

donate via btc or eth

btc: 18jCzwsZDGQYcs6Kyv92pd4683cnnxm1Dd
eth: 0xC285F21Cb271Cb4B3F70c4C47B2f7B26063AF590
paypal: paypal.me/mrcoles
comments powered by Disqus

Peter Coles

Peter Coles

is a software engineer who lives in NYC, works at Ringly, and blogs here.
More about Peter »

github · soundcloud · @lethys · rss

It’s time to get big money out of politics. Join the kick-started campaign to put government back in the hands of the people. Pledge mayday.us now