With AngularJS 1.3, the <base>
tag is required when in HTML5 mode and that got me thinking about what are the advantages/disadvantages of HTML5 mode vs Hash mode.
With Hash mode, the downside is that URLs are slightly ugly and not intuitive if you expect users to type URLs themselves. The downside of HTML5 mode (with 1.3) is that is requires the <base>
tag which can create a number of issues (like making working with SVG a bit of a pain).
Are there any other downsides to either modes that I am not thinking of?
Using the history API allows you to have a real URL that can have the appropriate content provided directly by the server.
This:
See also Breaking the Web With Hash Bangs.
The hashbang approach:
NB: Ancient browsers can fall back to simply following links to the server generated page when you use the History API.
That said, Angular's use of the History API is pretty poor.
Quotes below are from the documentation:
Using this mode requires URL rewriting on server side, basically you have to rewrite all your links to entry point of your application (e.g. index.html).
This advice is terrible. If you are using the history API, then you should be writing your server side code with progressive enhancement in mind. By rewriting every URL to an HTML document which bootstraps Angular and does nothing else, you making having different URLs that are handled by the server pointless. You also depend entirely on the JS working as there is no way to get the server to deliver the content when it fails.
In short, this approach uses the History API for purely cosmetic reasons and then uses a dirty hack to avoid 404 errors.
For browsers that support the HTML5 history API, $location uses the HTML5 history API to write path and search. If the history API is not supported by a browser, $location supplies a Hashbang URL.
This is the result of Angular following through with the philosophy that the History API is there for cosmetic, rather than practical, reasons. Instead of falling over to regular pages delivered by the server, Angular resorts to having two URLs (a History API one and a Hashbang one) for every resource.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With