5 ms·
Just FYI, most, if not all, of this is built into javascript already, via the DOM. http://www.joezimjs.com/javascript/the-lazy-mans-url-parsing/ http://www.joez
by bitsm 14y ago
Just FYI, most, if not all, of this is built into javascript already, via the DOM. http://www.joezimjs.com/javascript/the-lazy-mans-url-parsing/ http://www.joezimjs.com/javascript/the-lazy-mans-url-parsing...
- yahelc 14y agoAgreed, this is the way to do it. The only caveat is that IE has a bug where it omits the leading / on the pathname. You can normalize it with a simple one-liner: http://stackoverflow.com/a/6168370/172322 http://stackoverflow.com/a/6168370/172322
- lloeki 14y ago> Agreed, this is the way to do it. This sounds like arguing that we should use getElementById&al, addEventListener, and array.length with for loops instead of $('selector').on 'foo' and .each(). While this lib's inner code leaves to be desired in a number of ways, I really appreciate the readability and the lack of need to instantiate a full-blown DOM element then read a property to obtain a simple single result or two.
- yahelc 14y agoNot the same thing. jQuery is worth it if you're doing lots of DOM element selection. If the entirety of your usage of jQuery is a single $("#foo").bind(...) call, then it's probably not worth loading the entire library for that. URL parsing, for 90% of uses, tends to be a one-off need that doesn't really justify the addition of another library. Making decisions about what library to include is about trade-offs; this library is worth it if you need the query string sugaring or are doing lots of URL parsing. But "instantiating a full blown DOM element" to parse a single URL is over-stating the cost of the activity, especially when compared to adding an additional library to your application.
- lowboy 14y agoThis was my initial reaction as well, but I appreciate the qs/hash sugaring: http://www.domain.com/path/index.html?query1=test&silly=willy#test=hash&chucky=cheese $.url('?'); // query1=test&silly=willy $.url('?silly'); // willy $.url('?poo'); // (an empty string) $.url('#'); // test=hash&chucky=cheese $.url('#chucky'); // cheese $.url('#poo'); // (an empty string)
- mistercow 14y agoI think that's a bit too much functionality to put down as "sugar".