5

Should we do site.com/#!/blog or site.com/#!blog?

I understand there's no actual difference, however as a community of webdevelopers there should still be a conventional standard so that users can easily remember the url. If there's no already established standard, ideally someone will post an answer in favor of one and someone will post another in favor of another and one will get a lot more votes than the other...

Personally I prefer: site.com/#!blog simply because it's shorter. However I've seen many other sites use the other variant.

By the way, if your first instinct is to instruct us to not use hashbangs, then this question is not for you, please leave us alone.

Mark
  • 28,819
  • 33
  • 102
  • 136
  • 16
    That last paragraph really rubs "us" the wrong way. "We" just wanted to let you know that. And if you don't understand why, then please leave "us" alone. – Chris Jester-Young Mar 24 '11 at 05:06
  • 1
    @Chris I'm just trying to head off any off topic responses, thank you for entertaining my request. – Mark Mar 24 '11 at 05:09
  • @Mark: I'm just lampooning you for your use of the royal plural. :-P – Chris Jester-Young Mar 24 '11 at 05:10
  • @chris ^_^ @mark - This might be better posted in meta because of it's argumentative or discussion based nature. As for your question, since everything after the #! is supposed to be an identifier, `/blog` and `blog` should be two separate URIs – JohnP Mar 24 '11 at 05:11
  • I have to agree with Chris. I'm not a Javascript guy, I'll say that. But I know I have my issues where I think "I want A or B" and someone comes along with option C and... I can be a good developer and consider it, or I can be a tunnel-vision developer and tell them to sloph-off. I prefer to be a good developer! – corsiKa Mar 24 '11 at 05:13
  • 1
    For anyone interested in why to do hashbanging (sounds hot), please see this: http://code.google.com/web/ajaxcrawling/ – Jordan Mar 24 '11 at 05:13
  • @Jordan -- hashbanging *is* hot, and it's step n-3 in my n step plan to take over the world. – Malvolio Mar 24 '11 at 05:18
  • There's a hashbang tag now? Interesting (*read: dammit I missed an easy Taxonomist badge!*). – BoltClock Mar 24 '11 at 05:54

4 Answers4

10

You forgot the third option of site.com#!blog.

If you want to get all semantical, the question becomes "what does a '/' represent in a url?"

  • Does it represent a physical directory? [site.com#!blog]

When navigating a file system, folders are separated with slashes. This is the natural behavior on the web as well, but routing has changed this.

  • Does it represent a hierarchy of content? [site.com/#!blog]

outing introduced hierarchy of content. Instead of question marks and ampersands, query vars were separated with slashes creating a deep link structure based on what the developers feel is important.

  • Does it represent a separation of context within your url? [site.com/#!/blog]

Stack Overflow is a good example of what I mean by "separation of context". The URL of this question is [http://stackoverflow.com/questions/5414972/hashbang-slash-or-no-slash/]. The slash between the question ID and the question title isn't there because there is a file inside a folder named 5414972. There is only one question with the ID 5414972 so it isn't necessary for hierarchy either. It was a conscious choice to use a slash to separate the ID and the name rather than using any other delimiter such as a hyphen, underscore, or even no delimiter at all. A delimiter that isn't a slash would probably make the two variables resemble one. By putting slashes on either sides of the hash bang, the url becomes:

url prefix > ajax crawling notation > the specific page

rather than

url prefix > ajax crawling notation and the specific page.

Depending on what you answer yes to (and yes, it's subjective), you will have your answer. I think it's a little silly to try and get the entire world to agree on a standard for this when we still can't decide on how we should format dates.

As for that last little comment about resentment towards the "hash bang", I think you are imagining this. Who wouldn't like "hash bangs" when they sound so similar to "flash bangs"?

DingoEatingFuzz
  • 613
  • 3
  • 11
  • Can you provide a link which describes the various uses of slashes as 'physical directory' vs 'hierarchy of content' vs 'separation of context'. This is the first time I've heard of it. I'm dubious that people agree that's what those means. I didn't include the first possibility because I've never seen that used for a hashbang site, I don't believe it's a possibility in contention. – Mark Mar 24 '11 at 05:23
  • I don't think anyone has written about it, but I can explain where I'm coming from. Allow me to edit my answer. – DingoEatingFuzz Mar 24 '11 at 05:36
  • URL path defaults to /. site.com will be converted to site.com/ by any HTTP client. So arguing slash or no slash after domain is pointless. – smola Mar 18 '14 at 08:47
5

One slash is like one ant: when you see it, you expect to see another.

site.com/#!/blog is correct iff there's a site.com/#!/blog/latest , site.com/#!/blog/archive/october, or something like that in our future.

Just my €0.014185.

Malvolio
  • 38,966
  • 24
  • 87
  • 125
4

This depends on what you're doing. If you are basically just trying to ajaxify your site structure, then IMO it makes sense to include that root /, so /#!/blog. Popups, jumping through tabs, etc can use the other structure.

I don't believe there should be a conventional standard for this. There's a reason such tools as mod_rewrite exist: there are infinite solutions to infinite problems and attempting to standardize something as complex as URLs is impossible.

Also, for anyone wondering what a legitimate use is for hashbangs: http://code.google.com/web/ajaxcrawling/

Jordan
  • 29,324
  • 6
  • 51
  • 63
4

An advantage of using the slash is easier parsing. Without having to worry about whether a particular browser returns a "" or a "#" in case of a missing ("") or empty hash ("#"), you can simply take the first slash as your starting point: You don't have to worry about what's before it.

var tokens = window.location.hash.split("/").shift();

tokens becomes an array of tokens with [#]! already out of the way. Especially handy when you use a hierarchy of slash-delimited tokens in your hashes.

But of course, you should still check the stripped token to make sure it is a valid hashbang.

Ates Goral
  • 126,894
  • 24
  • 129
  • 188
  • 1
    I think most people use a routing library that already has this taken care of, eg sammy.js or backbone.js or similar. – Mark Mar 25 '11 at 08:21