Hash params vs url params, when to use which?

Url

Url Problem Overview


Is there a convention or best practice advice on when to use hash params, url params, vs paths?

For example:

  • hash params: stackoverflow.com/questions#q=13630937&t=hash-params-vs-url-params
  • url params: stackoverflow.com/questions?q=13630937&t=hash-params-vs-url-params
  • url path: stackoverflow.com/questions/13630937/hash-params-vs-url-params

Are there security, seo, usability benefits or disadvantages of each or is an issue of style?

Url Solutions


Solution 1 - Url

Hash params are useful for single page javascript applications, it allows javascript to present the user with a sharable url for state of the application. This is preferred because if you have a single page javascript application and users navigate and load more content via ajax and share the url, without the hash or a push state modification the person receiving the content would get the homepage or starting state. Hash params can be amended easily and read by javascript without reloading the page.

Hash parameters are usually only used on the client side, hash params wont be passed to the server... so they are only useful for parameterization to the client.

/users#!/13

would load the user index page and then javascript could read the hash

window.location.hash and pass it through some sort of client side router and make an appropriate ajax request and possibly load the user show template and push it to the dom.

Url params and url path are somewhat interchangeable. People usually use url path for describing restful resources such as

/users/[:id] => /users/13 => /users?id=13
/users/:id/posts => /users/13/posts
/users/:user_id/posts/:id => /users/13/posts/22
etc......

@Walter Tross, made a good point from an SEO point of view. Slugged urls or "URL Params" are more indexable by crawlers and tend to rank higher.

For params that do not fit in a resourceful route we send them as params

/users?sort=user_name&order=asc

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionwag2639View Question on Stackoverflow
Solution 1 - Urlj_mcnallyView Answer on Stackoverflow