NSWI142: Web Applications

Browser, tools, and a static website

Štěpán Stenchlák, KSI
stepan.stenchlak@matfyz.cuni.cz

Todays agenda

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

Credit Requirements

In order to get a credit you need to:

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

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?

Web browsers are available on almost every device and platform.

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

Demonstration: Browser

In this section we focus on so called "developer tools" and what they allow you to do.

  • Chromium based: Google Chrome, Microsoft Edge, any other cool AI browser
  • Firefox based: Mozilla Firefox, Brave
  • Safari

Basics

Try to open an HTML file from a local file and using http, https 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,Brave, Edge, ..)
  • open context menu (right click) and select "View page source"
  • ...

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 tab.

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
  • Find an IP address of youtube.com
    • Why YouTube has more IPv4 addresses?
    • Why those addresses differ based on geographical region?
  • 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 instruction 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. Add following content to the website <hr>, so it is visible in this form.

Use inline CSS to change header text color to red.

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

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" option.

Continue to the next slide once you are done.

Task Complete

Congratulation, if you have followed the instruction 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 in Linux, macOS, and Windows (Powershell).

  • 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 setup SSH keys for passwordless login.

curl

Command line tool to make HTTP requests. It is available on Linux, macOS, and Windows.

  • 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 127.0.0.1:8080
    

webik.ms.mff.cuni.cz

You can host your website at https://webik.ms.mff.cuni.cz/~<username>/. This servere 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 -P42222 index.html <username>@webik.ms.mff.cuni.cz:public_html/
      

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 (or more specifically 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 websites

Create a personal website presenting you as a student or a made up person / 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 websites 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.