Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Really basic question, but I'm hoping to get some clarity here.

Let's say I have a static website with some html, some css and basic javascript. No web app to back it up. When testing the website locally, why do I need to run a web server to serve the content to the browser?

Is it because the relative paths in the URLs used in web pages are relative to the folder where the server is retrieving the content from and thus the various files included from the central HTML page can't quite get located on the file-system?

share|improve this question
2  
A good example of when a static website works without a webserver is when you save a website, either from a browser (save page as) or with a tool like httrack or wget. Those cases do most of the things you're asking about. –  Journeyman Geek Jan 30 '13 at 2:15
add comment

1 Answer 1

up vote 5 down vote accepted

Can static websites be viewed without a server?

Yes.

No Surprise

When testing the website locally, why do I need to run a web server to serve the content to the browser?

You don't.

Is it because the relative paths in the URLs used in web pages are relative to the folder where the server is retrieving the content from and thus the various files included from the central HTML page can't quite get located on the file-system?

No.

share|improve this answer
    
Just to clarify, I'm aware that you can load any page on disk into your browser. However, will the local files linked in the html (e.g. <link href="css/mycss.css [...]/> or <script src="js/foo.js" [...]</script>) be referenced correctly? Is there a way to have the same URL work for both the way you showed, and when the same website is served through a server? –  glitch Jan 30 '13 at 2:08
    
@glitch It should just work. Your browser's security settings might be getting in the way -- i.e. it might disallow access to local files from a website. –  ta.speot.is Jan 30 '13 at 2:09
1  
Great, thanks for taking the time to put that together :) –  glitch Jan 30 '13 at 2:25
1  
Back in ancient times before we added a CGI shopping cart, this was the way we tested for broken links. Xenu link sleuth on a local disk copy beat wasting time on the slow internet of the day. After implementing the shopping cart, we had to build an internal test server for running the CGI efficently for testing. –  Fiasco Labs Jan 30 '13 at 2:53
2  
@glitch // is protocol-relative, so I think you'll end up with file://[whatever]/ajax.googleapis.com/.... Which is what you're asking for. –  ta.speot.is Jan 30 '13 at 6:39
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.