You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: tutorial.md
+31-18
Original file line number
Diff line number
Diff line change
@@ -30,14 +30,13 @@ The browser communicates with the web server via a protocol known as HTTP. When
30
30
| |
31
31
```
32
32
33
-
> If this is your first encounter with web development, the Mozilla Developer Network has great
34
-
> tutorials about the [history of the web](https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web/The_web_and_web_standards),
35
-
> [how the Internet works](https://developer.mozilla.org/en-US/docs/Learn/Common_questions/Web_mechanics/How_does_the_Internet_work),
36
-
> and [getting started with the web](https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web)
37
-
> that are worth checking out.
38
-
>
39
-
> The book "Broad Band - The Untold Story of the Women Who Made the Internet" by Claire L. Evans is also a fascinating
40
-
> story of the people and communities that made the Internet what it is today.
33
+
If this is your first encounter with web development the following are good pieces to learn more about the history of the internet and the world wide web:
34
+
35
+
*[History of the web](https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web/The_web_and_web_standards)
36
+
*[How the Internet works](https://developer.mozilla.org/en-US/docs/Learn/Common_questions/Web_mechanics/How_does_the_Internet_work),
37
+
*[Getting started with the web](https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web)
38
+
* The book [Broad Band - The Untold Story of the Women Who Made the Internet](https://catalog.princeton.edu/catalog/99108000433506421) by Claire L. Evans is also a fascinating story of the people and communities that made the Internet what it is today.
39
+
*[The birth of the Web](https://home.web.cern.ch/science/computing/birth-web) at CERN where you can view a copy of the very first web site.
41
40
42
41
We'll dive into the details of HTTP at a later point, but to get started let's look closely at HTML first.
43
42
@@ -220,23 +219,26 @@ The talk [Everything You Know About Web Design Just Changed](https://www.youtube
220
219
### CSS - using an external file
221
220
In our previous examples we inserted the CSS for our pages right on the `<head>...</head>` section of the HTML page.
222
221
223
-
Another common way to insert CSS inside a page is to *reference an external file* that has the CSS that we would normally put in the `<style>...</style>` section. For example, let's look at the `<head>...</head>` section of our `hello-world-bootstrap.html` page, notice that it looks like this:
222
+
Another common way to insert CSS inside a page is to *reference an external file* that has the CSS that we would normally put in the `<style>...</style>` section. For example, let's replace the `<head>...</head>` section of our `hello-world-fancy.html` page to look like this:
The `<link>` element tells the browser to load the CSS styles from the URL indicated. This particular example is using the CSS defined by [Bootstrap](https://getbootstrap.com/) which is a popular toolkit for frontend development. The HTML content in the `hello-world-bootstrap.html` file references several CSS class defined by Bootstrap, notice the `class="container"`, `class="row"`, `class="col"` on that HTML file.
232
+
The `<link>` element tells the browser to load the CSS styles from the URL indicated. This particular example is using the CSS defined by [new.css](https://github.com/xz/new.css) which is a very small framework for frontend development that uses "some sensible defaults and styles your HTML to look reasonable".
233
+
234
+
Refresh your browser to view the `hello-world-fancy.html` page with the new defaults.
233
235
234
236
235
237
## Leaving file:// behind
236
238
237
-
If you look at the address bar in your browser while you have the `hello_world.html` loaded you'll notice that it says something along the lines of `file:///something/.../hello-world.html`.
239
+
If you look at the address bar in your browser while you have the `hello-world-fancy.html` loaded you'll notice that it says something along the lines of `file:///something/.../hello-world-fancy.html`.
238
240
239
-
The `file://` at the beginning of the URL indicates that the browser is accessing this file via the "file protocol". However, when you visit a website, say https://wikipedia.org, you'll notice that the URL will start with `http://` (or `https://`) rather than `file://`.
241
+
The `file://` at the beginning of the URL indicates that the browser is accessing this file via the "file protocol". However, when you visit a website, say https://wikipedia.org, you would notice that the URL starts with `http://` (or `https://`) rather than `file://`.
240
242
241
243
The file protocol is fine for loading simple HTML pages from our local disk, but for web development we use the HTTP protocol which allows us to load HTML pages from remote servers. In the example above the URL `https://wikipedia.org` tells the browser to fetch the Wikipedia home page via the network (rather than fetching it from a file on our local disk.)
242
244
@@ -404,6 +406,19 @@ end
404
406
405
407
The important thing about this application is that we could put it on a different server (rather than on our own laptop) and make it available for the world to access, say via a URL like `http://my-first-ruby-application.org`. We are not going to this now, but the fact that this application uses HTTP as its communication protocol and produces HTML means that we could.
406
408
409
+
> The 3000 in the URL http://localhost:3000/ designates the port the browser will
410
+
> use to talk to our `localhost` server. If we don't indicate a port in the URL
411
+
> (e.g. http://wikipedia.org) the browser by default will use port 80 and will
412
+
> issue http://wikipedia.org:80 behind the scenes.
413
+
>
414
+
> Our little Ruby program is hard-coded to listen on port `3000`, see line
415
+
> `set :port, 3000` in `webdemo1.rb`.
416
+
>
417
+
> Port numbers below 1024 are reserved in most operating systems and
418
+
> [require administrative privileges to be accessed](https://stackoverflow.com/questions/10182798/why-are-ports-below-1024-privileged).
419
+
> To work around that security restriction developers typically use port
420
+
> numbers like 3000 or 8080 during development.
421
+
407
422
For now, type `CTRL-C` from your terminal to shut down this application. You'll see the following output in the terminal:
408
423
409
424
```
@@ -428,11 +443,11 @@ get("/fancy") do
428
443
end
429
444
```
430
445
431
-
By default the ERB file is expected to be found in the `./views` folder. In fact you can open this file in VS Code and you'll notice that is an almost identical copy to the `hello_world_fancy.html` that we used at the beginning of the workshop.
446
+
By default the ERB file is expected to be found in the `./views` folder. In fact you can open this file in VS Code and you'll notice that is an almost identical copy to the `hello-world-fancy.html` that we used at the beginning of the workshop.
432
447
433
448
We can run this new demo by running `ruby webdemo2.rb` from the Terminal window and pointing our browser again to http://localhost:3000/fancy
434
449
435
-
Notice how it looks just like our previous `hello_world_fancy.html` page, but again, this time the page is served via HTTP (rather than via the file system).
450
+
Notice how it looks just like our previous `hello-world-fancy.html` page, but again, this time the page is served via HTTP (rather than via the file system).
436
451
437
452
Another thing that is not obvious in the code but that is important to notice is the page rendered at http://localhost:3000/fancy is using some CSS styling, but there is no `<style>...</style>` section defined in our `fancy.erb` file. Where is this styling coming from?
438
453
@@ -649,5 +664,3 @@ Similarly to what we did with CSS, it is also possible to load external JavaScri
649
664
```
650
665
651
666
however, the order in which JavaScript is loaded and executed is important and something that has to be kept in mind when loading from an external source from the `<head>...</head>` section of the page. If we load and execute the JavaScript before the HTML elements are rendered on the page the code won't be able to find them. There are many ways of working around this issue, and libraries like [jQuery](https://jquery.com/) take care of it rather nicely, just be aware of this.
0 commit comments