HTML Flashcards

1
Q

What does a DOCTYPE do?

A

HTML document type declaration. It is the first line of code required for HTML or XHTML document. The DOCTYPE declaration is an instruction to the web browser about what version HTML the page is written in. This ensures that the web page is parsed the same way by different web browsers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you serve a page with content in multiple languages?

A

When an HTTP request is made to a server, the requesting user agent usually sends information about language preferences, such as in the Accept-Language header. The server can then use this information to return a version of the document in the appropriate language if such an alternative is available. The returned HTML document should also declare the lang attribute in the tag, such as ….

In the back end, the HTML markup will contain i18n placeholders and content for the specific language stored in YML or JSON formats. The server then dynamically generates the HTML page with content in that particular language, usually with the help of a back end framework.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What kind of things must you be wary of when designing or developing for multilingual sites?

A

-Use lang attribute in your HTML.
-Directing users to their native language — Allow a user to change his country/language easily without hassle.
-Text in images is not a scalable approach — Placing text in an image is still a popular way to get good-looking, non-system fonts to display on any computer. However to translate image text, each string of text will need to have it’s a separate image created for each language. Anything more than a handful of replacements like this can quickly get out of control.
-Restrictive words / sentence length — Some content can be longer when written in another language. Be wary of layout or overflow issues in the design. It’s best to avoid designing where the amount of text would make or break a design. Character counts come into play with things like headlines, labels, and buttons. They are less of an issue with free flowing text such as body text or comments.
-Be mindful of how colors are perceived — Colors are perceived differently across languages and cultures. The design should use color appropriately.
Formatting dates and currencies — Calendar dates are sometimes presented in different ways. Eg. “May 31, 2012” in the U.S. vs. “31 May 2012” in parts of Europe.
-Do not concatenate translated strings — Do not do anything like “The date today is “ + date. It will break in languages with different word order. Using template parameters instead.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are data- attributes good for?

A

Before JavaScript frameworks became popular, front end developers used data- attributes to store extra data within the DOM itself, without other hacks such as non-standard attributes, extra properties on the DOM. It is intended to store custom data private to the page or application, for which there are no more appropriate attributes or elements.

These days, using data- attributes is generally not encouraged. One reason is that users can modify the data attribute easily by using inspect element in the browser. The data model is better stored within JavaScript itself and stay updated with the DOM via data binding possibly through a library or a framework.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Consider HTML5 as an open web platform. What are the building blocks of HTML5?

A
  • Semantics — Allowing you to describe more precisely what your content is.
  • Connectivity — Allowing you to communicate with the server in new and innovative ways.
  • Offline and storage — Allowing webpages to store data on the client-side locally and operate offline more efficiently.
  • Multimedia — Making video and audio first-class citizens in the Open Web.
  • 2D/3D graphics and effects — Allowing a much more diverse range of presentation options.
  • Performance and integration — Providing greater speed optimization and better usage of computer hardware.
  • Device access — Allowing for the usage of various input and output devices.
  • Styling — Letting authors write more sophisticated themes.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Describe the difference between a cookie, sessionStorage and localStorage.

-Cookie

A
Initiator — Client or server. Server can use Set-Cookieheader
Expiry — Manually set
Persistent across browser sessions —
Depends on whether expiration is set
Have domain associated — Yes
Sent to server with every HTTP request — Yes
Capacity (per domain) — 4kb
Accessibility — Any window
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Describe the difference between a cookie, sessionStorage and localStorage.

-SessionStorage

A
Initiator — Client
Expiry — On tab close
Persistent across browser sessions — No
Have domain associated — No
Sent to server with every HTTP request — No
Capacity (per domain) — 5MB
Accessibility — Same tab
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Describe the difference between a cookie, sessionStorage and localStorage.

-LocalStorage

A
Initiator — Client
Expiry — Forever
Persistent across browser sessions — Yes
Have domain associated — No
Sent to server with every HTTP request — No
Capacity (per domain) — 5MB
Accessibility — Any window
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Describe the difference between script, script async, and script defer

A

script - HTML parsing is blocked, the script is fetched and executed immediately, HTML parsing resumes after the script is executed.

script async - The script will be fetched in parallel to HTML parsing and executed as soon as it is available (potentially before HTML parsing completes). Use async when the script is independent of any other scripts on the page, for example, analytics.

script defer - The script will be fetched in parallel to HTML parsing and executed when the page has finished parsing. If there are multiple of them, each deferred script is executed in the order they were encountered in the document. If a script relies on a fully-parsed DOM, the defer attribute will be useful in ensuring that the HTML is fully parsed before executing. A deferred script must not contain document.write.

Note: The async and defer attributes are ignored for scripts that have no src attribute.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Why is it generally a good idea to position CSS links between head and JS scriptss just before body? Do you know any exceptions?

A

Placing links in the head

Putting links in the head is part of proper specification in building an optimized website. When a page first loads, HTML and CSS are being parsed simultaneously; HTML creates the DOM (Document Object Model) and CSS creates the CSSOM (CSS Object Model). Both are needed to create the visuals in a website, allowing for a quick “first meaningful paint” timing. This progressive rendering is a category optimization sites are measured in their performance scores. Putting stylesheets near the bottom of the document prohibits progressive rendering in many browsers.

Placing scripts just before body

script tags block HTML parsing while they are being downloaded and executed which can slow down your page. Placing the scripts at the bottom will allow the HTML to be parsed and displayed to the user first.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is progressive rendering?

A

Progressive rendering is the name given to techniques used to improve the performance of a webpage (in particular, improve perceived load time) to render content for display as quickly as possible.

It used to be much more prevalent in the days before broadband internet but it is still used in modern development as mobile data connections are becoming increasingly popular (and unreliable)!

Examples of such techniques:

  • Lazy loading of images - Images on the page are not loaded all at once. JavaScript will be used to load an image when the user scrolls into the part of the page that displays the image.
  • Prioritizing visible content (or above-the-fold rendering) - Include only the minimum CSS/content/scripts necessary for the amount of page that would be rendered in the users browser first to display as quickly as possible, you can then use deferred scripts or listen for the DOMContentLoaded/load event to load in other resources and content.
  • Async HTML fragments - Flushing parts of the HTML to the browser as the page is constructed on the back end. More details on the technique can be found here.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Why you would use a srcset attribute in an image tag? Explain the process the browser uses when evaluating the content of this attribute.

A

You would use the srcset attribute when you want to serve different images to users depending on their device display width - serve higher quality images to devices with retina display enhances the user experience while serving lower resolution images to low-end devices increase performance and decrease data wastage (because serving a larger image will not have any visible difference). For example: <img></img> tells the browser to display the small, medium or large .jpg graphic depending on the client’s resolution. The first value is the image name and the second is the width of the image in pixels. For a device width of 320px, the following calculations are made:

500 / 320 = 1.5625
1000 / 320 = 3.125
2000 / 320 = 6.25
If the client’s resolution is 1x, 1.5625 is the closest, and 500w corresponding to small.jpg will be selected by the browser.

If the resolution is retina (2x), the browser will use the closest resolution above the minimum. Meaning it will not choose the 500w (1.5625) because it is greater than 1 and the image might look bad. The browser would then choose the image with a resulting ratio closer to 2 which is 1000w (3.125).

srcsets solve the problem whereby you want to serve smaller image files to narrow screen devices, as they don’t need huge images like desktop displays do — and also optionally that you want to serve different resolution images to high density/low-density screens.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly