52
8
I am unclear if an anchor tag should come before a query string or after.
http://www.domain.com/search?query=hello#name
or
http://www.domain.com/search#name?query=hello
Or does it matter?
52
8
I am unclear if an anchor tag should come before a query string or after.
http://www.domain.com/search?query=hello#name
or
http://www.domain.com/search#name?query=hello
Or does it matter?
63
Best practice is to append the named anchor at the end. The technical name is a fragment identifier, and the syntax is in RFC 3986.
The RFC section is here: http://tools.ietf.org/html/rfc3986#section-4.1
relative-ref = relative-part [ "?" query ] [ "#" fragment ]
Wikipedia actually covers it well:
The fragment identifier introduced by a hash mark # is the optional last part of a URL for a document
Cheers @iivel! Section 3 was more helpful for me (section-4.1 seems specific to relative URIs) as I debated this with someone.
– eebbesen – 2015-05-19T19:03:46.740What about webserver, does it need to handle it during serving page ? – Behrouz.M – 2016-05-17T12:12:44.783
1@raypixar URL fragments are not sent to the server – Juan Mendes – 2016-07-07T17:36:49.627
1Test it. Only one of them works, so it does matter. When I tried anchor first then it thinks the ? is part of the "#" fragment and thus doesn't hop to the right anchor (since there isn't one that has ? in its name...) and probably wouldn't include any info if I checked for the query string in PHP. The last one I haven't tested. – Julix – 2017-09-21T17:10:03.447