NSWI142: Web Applications

Browser, tools, and a static website

Jáchym Bártík, KSI
jachym.bartik@matfyz.cuni.cz

Today's agenda

  • labs organization
  • quick recap of TCP/IP, IPv4, IPv6, ports
  • domains, DNS
  • introduction to HTTP(s), HTML, CSS

Credit Requirements

To get credit, you have to:

  • successfully solve mandatory homework assignments,
  • implement semestral project,
  • pass the credit test.

During the practicals, you can collect points for active participation and solving homeworks. By collecting enough points, you can improve your final grade or even pass without the need to take the final exam.

For more details, see grading.

Why web applications?

They are available on almost every device and platform.

  • Websites: Wikipedia, Google, Novinky.cz
  • Browser applications: Google Docs, Microsoft Office Online
  • Electron based desktop apps: VS Code, Discord, Figma, Slack, MS Teams
  • Mobile apps: PWA
  • Backend solutions: Node.js, Deno, Bun

Browser

In this section, we focus on so called "developer tools" and what they allow you to do. First, pick your favorite browser:

  • Chromium based: Google Chrome, Microsoft Edge, Brave
  • Firefox based: Mozilla Firefox, LibreWolf
  • Safari

Basics

Try to open a browser page from a local HTML file using http protocol.

Pick a website and inspect the source code. You can even pick the default content in a new tab and see what is there.

  • ctrl+u (Chrome, Firefox, Edge, ..)
  • open context menu (right click) and select "View page source"
  • ...

Demonstration: Developer tools

In most modern, browsers you can open a developer tools console. There are multiple ways to do so.

  • open context menu (right click) and select "Inspect"
  • F12
  • ctrl+shift+i
  • ...

Explore Elements, Network, and Application tabs.

TCP/IP

  • Each machine has an IPv4 and/or IPv6 address.
    • 127.0.0.1, 77.75.79.222
    • ::1, 2a02:598:a::79:222
  • Humans prefer domain names.
    • cz - Top level domain
    • cuni.cz - Second-level domain (.cz 200 CZK/year, .com 350 CZK/year)
    • mff.cuni.cz
    • ms.mff.cuni.cz
  • Try find some IP addresses:
    • Google: DNS resolver
    • Linux: dig youtube.com
    • Powershell: Resolve-DnsName youtube.com

Exercise: Static website

Create a simple static website as a single HTML file. You should already know how to do this. Before you start, please read instructions on following slides and proceed accordingly.

Create a static website

Create a local file content.html. Add a header, a paragraph, a link, a footer, and a button with no action into the website. The link should be in the header. The footer should contain copyright notice.

Use inline CSS to change header text color to red.

Open the website in a browser of choice and check everything looks as it should.

Continue to the next slide once you are done.

Semantic HTML elements

Use following semantic elements in you website:

Continue to the next slide once you are done.

Validation

Utilize validator.w3.org to validate your website and fix any errors or warning. Use "Validate by File Upload" or "Validate by Direct Input" options.

Continue to the next slide once you are done.

Task Complete

Congratulation, if you have followed the instructions, you just reached the end of this exercise.

Debriefing

  • Any issues?
  • Why we need validation? Can browser handle an invalid document?

Demonstration: Tools

In this section we recap some of the tools you already know, namely ssh and scp. We also add a new one to make HTTP requests.

ssh

Should work the same on Linux, macOS, and Windows.

  • Connect to remove server:
  • 
            ssh -p <port> <username>@<hostname>
          
  • Proxy remote port to localhost:
  • 
            ssh -L <local port>:localhost:<remote port> -p <port> <username>@<hostname>
            # Example: 8080:localhost:80
          

scp

Again, should be supported by all major platforms.

  • Copy a file to a remove server:
  • 
            scp -P <port> <local file> <username>@<hostname>:<remote path>
          
  • Copy a directory to a remove server:
  • 
            scp -r -P <port> <local directory> <username>@<hostname>:<remote path>
          

Edit ~/.ssh/config to avoid typing the same information over and over again. Also, set up SSH keys for passwordless login.

curl

Command line tool to make HTTP requests. It's available on all major platforms.

  • Execute HTTP GET request.
  • Execute HTTP POST request.
  • Send JSON file using HTTP POST request.

Demonstration: Webhosting

localhost

You can host your website locally. This is quick and easy way to develop and test a website.


      # Python
      python -m http.server 8080

      # PHP
      php -S localhost:8080
    

webik.ms.mff.cuni.cz

You can host your website at https://webik.ms.mff.cuni.cz/~<username>/. This server is provided by NSWI142, do not use or abuse it for anything else! You should have received username and password by e-mail.

Connect using SSH to get access to shell:

        ssh -p 42222 <username>@webik.ms.mff.cuni.cz
      

Copy file index.html from local machine to webik:

        scp -P 42222 index.html <username>@webik.ms.mff.cuni.cz:public_html/
      

Anything in your public_html directory is publicly available.

ms.mff.cuni.cz

You can host your website at https://www.ms.mff.cuni.cz/~<username>/. This service has nothing to do with NSWI142.

The following information is based on NSWI177.

  • SU1 : u1-1.ms.mff.cuni.cz - u1-14.ms.mff.cuni.cz
  • SU2 : u2-2.ms.mff.cuni.cz - u2-5.ms.mff.cuni.cz
  • Rotunda : u-pl1.ms.mff.cuni.cz - u-pl2.ms.mff.cuni.cz

The computers in Lab SU1 and SU2 can not be connected to via SSH during the day (i.e., during the scheduled classes). That is to prevent remote users to interfere with classes. Rotunda lab machines are accessible 24/7.

Exercise: Upload your website to webik

The objective is to create a simple personal website and publish it using webik.

Create a personal website

Create a personal website presenting you as a student or a made up characeter. You need to have a landing page (./personal/index.html), about page (./personal/about.html) and projects page (./personal/projects.html). They all need to be interlinked using relative links. You are free to use external CSS of your choice or create your own.

Make sure that the HTML is valid!

Do not use any JavaScript!

Upload all the files into your public_html directory. Make sure that all the pages work.

Resources

In this section you can find additional resources connected to the topic of this practical.

Resources

Questions, ideas, or any other feedback?

Please feel free to use the anonymous feedback form.