Using a Web server

Most of the examples in this book consist of a single file (not considering the external libraries loaded using the <script> tags), and you can run them by simply opening them in a browser. You don't even need a Web server. Just click on the file and view it in your browser. But this won't work in examples that load external files via Ajax. For those files, you do need a Web server.

If you are using an HTML editor, such as PHPStorm or Brackets, it automatically starts a Web server for you and serves the page to your default browser. If you have Python installed in your system (it is native in macOS and Linux, and you can install it in Windows), you can run a simple server from the directory where your files are installed. The syntax depends on which Python version you have installed. You can check by opening a console and typing:

python -v

Now move to the directory where your HTML files are stored and run one of the following commands. If you have Python 3.x , run:

python3 -m http.server

If your version is 2.x, run:

python -m SimpleHTTPServer

Now you can open your files using http://localhost:8080/your-file-name.html.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset