Can static websites be viewed without a server?
Can static websites be viewed without a server?
Yes.
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.
Static websites can be viewed without a server, locally, simply by opening them up in a web browser, and you can do whole big websites this way if you want. But there are limitations and drawbacks, which is why people and systems use local servers for static websites.
One of the reasons you may be asking is because using many of the popular static site generators, like Jekyll, requires that you tell the system to --serve
it (or similar), creating a local server for the static site. But if it's static, why do you need a server?
Here are a few reasons:
- only relative links are safe (
/
as a link to home is broken, as is referencing/css/something.css
, since/
is the root of your computer, not the site); - relatedly, directory-level links fail (
blog/
shows the files under that directory, instead of looking forblog/index.html
or similar); - and browsers treat local files differently among themselves and between them and hosted files (Chrome limits AJAX calls, IE uses a different protocol from everyone else, etc.).
So, no, you don't need it, but you do need it if you want those things.