TIL About URL
What is URL?
URL stands for Uniform Resource Locator. URLs are the address of the websites. URL mostly contain Latin characters. Some URL contain non Latin characters, they are known as international domain. Though browsers now can convert international domain into Latin characters.
Anatomy of URL
Protocol
Protocol is used to tell the browser which protocol should be used for the communication. Two most commonly used protocols are http and https. Protocols are always in the beginning of the URL.
Subdomain
Subdomain appears after ‘://’ and before the first ‘.’ of the URL. The most common subdomain is ‘www’ or world wide web. Earlier it was necessary to use subdomain in your URL but nowadays you can use URL without subdomain.
Domain
Domain appears between the first two ‘.’ of the URL. Domain is used to identify the site. It is usually same as the name of site.
TLD
TLD stands for Top Level Domain. It is also called extension. TLD are usually used to denote the type of organisation or the country specific site. For example, “com” is the most common TLD, com is used to denote the organisation is commercial. Other examples of TLD are .org, .net, .biz, .in, .us, and many more similar TLD.
Subfolder
Subfolder is part of file path. It shows the directory of the file. Initially when you create a website. You access the file using the path of the file, something like this localhost:8000/my-website/index.html. In this my-website is the directory and index.html is the file name. In sites with SEO friendly URL, file name and even actual directory structure is avoided.
Slug
Slug is used to identify a specific page in a website. For example, in “https://tilincode.substack.com/p/til-how-to-add-emojis-on-your-website” til-how-to-add-emojis-on-your-website is the the slug which identifies the page this slug will take you to. They are widely used in blogging sites and forums.
Query Parameters
Query parameters are used to send information to the browser through the URL. They start with ‘?’. Query parameters are key-value pair which are separated by ‘=’. Multiple query parameters can be sent by separating each query parameter by ‘&’. Query parameter can be used for multiple purposes like:
Filtering: Remove unwanted data from the page. For example, color=red will let the code know that user wants to see only red colored products.
Source: When a site wants to know where the traffic is coming from or they are having an affiliate program. They can use query parameters to identify the source. For example, utm_source=ref100.
Sorting: Sorting information can be given through url. For example, sort=ASC will let the code know that the sorting order should be ascending.
The code decides how the query parameters are processed. Query parameters can understandable by people or they might not be.
Query Parameters can be content modifying or tracking. Filtering is a type of content modifying query parameter and source is a type of tracking query parameter.
Fragment
Some URL contain fragments as well. Fragments begin with ‘#’. Fragment are used to identify specific portion of the site.