hashbang slash or no slash? [closed]
Asked Answered
A

4

6

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.

Atmosphere answered 24/3, 2011 at 4:59 Comment(8)
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.Anomalous
@Chris I'm just trying to head off any off topic responses, thank you for entertaining my request.Atmosphere
@Mark: I'm just lampooning you for your use of the royal plural. :-PAnomalous
@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 URIsInterdictory
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!Jenicejeniece
For anyone interested in why to do hashbanging (sounds hot), please see this: code.google.com/web/ajaxcrawlingPerplexity
@Perplexity -- hashbanging is hot, and it's step n-3 in my n step plan to take over the world.Involved
There's a hashbang tag now? Interesting (read: dammit I missed an easy Taxonomist badge!).Milena
N
11

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 [https://mcmap.net/q/1590565/-hashbang-slash-or-no-slash-closed/]. 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"?

Nescience answered 24/3, 2011 at 5:15 Comment(3)
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.Atmosphere
I don't think anyone has written about it, but I can explain where I'm coming from. Allow me to edit my answer.Nescience
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.With
I
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.

Involved answered 24/3, 2011 at 5:16 Comment(0)
P
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/

Perplexity answered 24/3, 2011 at 5:12 Comment(0)
E
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.

Ectomere answered 24/3, 2011 at 5:16 Comment(1)
I think most people use a routing library that already has this taken care of, eg sammy.js or backbone.js or similar.Atmosphere

© 2022 - 2024 — McMap. All rights reserved.