Hashtags (fragment identifiers) API VS Javascript History

Which one is better? Using fragment identifiers ...

http://www.alinkthatdoesnotwork.com/#!/dir1/dir2/file.html 

... or the new JavaScript history API?

 https://github.com/examplethatdoesnotwork/project/src/script.js 

Or should I use both? (via backup)

aspects of:

  • Compatibility / Support
  • Speed
  • Convenience
+6
source share
5 answers

Hashtags is a way to categorize content on Twitter, you mean fragment identifiers.

Using fragment identifiers to indicate which content to download via Ajax is a terrible idea. This is a hack that is fragile, the search engine is unfriendly (except with a lot of hacks on both sides) and depends on JavaScript .

The story API is a reliable system that is actually designed to do the job. The only problem with it is browser support , but (unlike the fragment identifier approach), it competently degrades to real URIs that will be transferred directly to your server (which is what Github does ).

Even Twitter seems to be about to switch to the story API .

+2
source

The story API is significantly preferable if normal links usually work in browsers that don't support it.

You can use a library such as History.js to enable it in these browsers.

More info here: This is about hash bangs , Side effects of the -Bang URL hash .

In short, URLs are important. URLs are forever, and cool URLs do not change, and finally: After you hashbang, you cannot return.

+1
source

New storytelling methods are incredibly useful for AJAX navigation. For example, pushState or replaceState allow you to update your browser’s address bar so that the user sees a clean URL instead of an ugly hash.

However, as I am sure, you know, support for the new API is still limited. location.hash is much more widely supported at this stage, which means that you have to write a hash reserve for browsers that cannot use the new window.history properties.

+1
source

I think the question is what is support. For now, you cannot use the history API just because IE is not supported. You will need a backup solution such as GitHub.

0
source

You have indicated "compatibility" as your first criterion. Since the history API is not yet supported by all major providers (I'm looking at you, Microsoft), not even in their most recent releases (IE9 does not), which pretty much means that you should use a hash. (This is very bad, but we are there.) And this is not only Microsoft, many mobile devices use one or two versions of their mobile browser, and therefore do not have this.

0
source

Source: https://habr.com/ru/post/909159/


All Articles