EN
JavaScript - hash parameters vs query parameters
3
points
In this article, we would like to show you the difference between hash parameters and query parameters.
Quick overview:
Hash parameters
- appear after the path and query parameters (as the last URL part),
- start withÂ
#
character in the URL, - can be accessed only from a web browser JavaScript API,
- change can be detected with the hashchange event,
- any changes from the web browser address bar do not cause website reloading,
- are not very good for SEO as they require interpretation by the web browser engine,
- are useful for SPA routing (single-page applications).
Format:
#parameter1=value1¶meter2=value2
When to use:
When we have a front-end application that does not have any backend, when a website is built only as static content.
Query parameters
- appear after the path,
- start with
?
 character in the URL, - can be accessed both from the web browser JavaScript API and from the server-side (are sent in HTTP request),
- any changes from the web browser addres bar cause website reloading (unless we use the
history()
API which prevents the reload), - are useful for SPA routing (single page applications)
Format:
?parameter1=value1¶meter2=value2
When to use:
- When we want to have better SEO,
- with server-side rendering, when we are able to generate the page on the server-side.
Â