Can static websites be viewed without a server?











up vote
6
down vote

favorite
1












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















up vote
6
down vote

favorite
1












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













up vote
6
down vote

favorite
1









up vote
6
down vote

favorite
1






1





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













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?







website webserver






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 30 '13 at 2:02









glitch

405168




405168








  • 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














  • 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








2




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




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










2 Answers
2






active

oldest

votes

















up vote
4
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






  • 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






  • 1




    This answer is pat to the point of being wrong. You can absolutely put whole static websites together without serving them, but relative-vs-absolute links, as you suspect, @glitch, AND differences in how browsers treat local files (protocols differ, sandbagging happens) are why people use static local servers.
    – D_N
    Dec 3 '15 at 4:32




















up vote
4
down vote













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 for blog/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.






share|improve this answer























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "3"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f543744%2fcan-static-websites-be-viewed-without-a-server%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    4
    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






    • 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






    • 1




      This answer is pat to the point of being wrong. You can absolutely put whole static websites together without serving them, but relative-vs-absolute links, as you suspect, @glitch, AND differences in how browsers treat local files (protocols differ, sandbagging happens) are why people use static local servers.
      – D_N
      Dec 3 '15 at 4:32

















    up vote
    4
    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






    • 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






    • 1




      This answer is pat to the point of being wrong. You can absolutely put whole static websites together without serving them, but relative-vs-absolute links, as you suspect, @glitch, AND differences in how browsers treat local files (protocols differ, sandbagging happens) are why people use static local servers.
      – D_N
      Dec 3 '15 at 4:32















    up vote
    4
    down vote



    accepted







    up vote
    4
    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















    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














    share|improve this answer



    share|improve this answer








    edited Jan 30 '13 at 2:18

























    answered Jan 30 '13 at 2:04









    ta.speot.is

    13.4k22546




    13.4k22546












    • 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






    • 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






    • 1




      This answer is pat to the point of being wrong. You can absolutely put whole static websites together without serving them, but relative-vs-absolute links, as you suspect, @glitch, AND differences in how browsers treat local files (protocols differ, sandbagging happens) are why people use static local servers.
      – D_N
      Dec 3 '15 at 4:32




















    • 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






    • 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






    • 1




      This answer is pat to the point of being wrong. You can absolutely put whole static websites together without serving them, but relative-vs-absolute links, as you suspect, @glitch, AND differences in how browsers treat local files (protocols differ, sandbagging happens) are why people use static local servers.
      – D_N
      Dec 3 '15 at 4:32


















    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




    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




    1




    1




    Great, thanks for taking the time to put that together :)
    – glitch
    Jan 30 '13 at 2:25




    Great, thanks for taking the time to put that together :)
    – glitch
    Jan 30 '13 at 2:25




    1




    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






    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




    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




    @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




    1




    1




    This answer is pat to the point of being wrong. You can absolutely put whole static websites together without serving them, but relative-vs-absolute links, as you suspect, @glitch, AND differences in how browsers treat local files (protocols differ, sandbagging happens) are why people use static local servers.
    – D_N
    Dec 3 '15 at 4:32






    This answer is pat to the point of being wrong. You can absolutely put whole static websites together without serving them, but relative-vs-absolute links, as you suspect, @glitch, AND differences in how browsers treat local files (protocols differ, sandbagging happens) are why people use static local servers.
    – D_N
    Dec 3 '15 at 4:32














    up vote
    4
    down vote













    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 for blog/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.






    share|improve this answer



























      up vote
      4
      down vote













      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 for blog/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.






      share|improve this answer

























        up vote
        4
        down vote










        up vote
        4
        down vote









        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 for blog/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.






        share|improve this answer














        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 for blog/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.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 30 at 0:25

























        answered Dec 3 '15 at 6:25









        D_N

        1405




        1405






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Super User!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f543744%2fcan-static-websites-be-viewed-without-a-server%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            Origin of the phrase “under your belt”?