<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Parsing URLs with the DOM!</title>
	<atom:link href="http://james.padolsey.com/javascript/parsing-urls-with-the-dom/feed/" rel="self" type="application/rss+xml" />
	<link>http://james.padolsey.com/javascript/parsing-urls-with-the-dom/</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Thu, 02 Feb 2012 18:03:26 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
	<item>
		<title>By: Supersha</title>
		<link>http://james.padolsey.com/javascript/parsing-urls-with-the-dom/comment-page-1/#comment-23580</link>
		<dc:creator>Supersha</dc:creator>
		<pubDate>Tue, 03 Nov 2009 12:44:12 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=572#comment-23580</guid>
		<description>Hi,James,I found sth error in your parseURL method,if uses your method in IE,the &quot;file&quot; property will return a empty string like that:&quot;http://www.jsparadise.cn:8080/index.html?id=123&amp;pages=4&quot;.
so I change the RegExp like that:
&quot;file: (a.pathname.match(/\/?([^\/?#]+)$/i) &#124;&#124; [,&#039;&#039;])[1]&quot;,it will solve this problem. ^_^</description>
		<content:encoded><![CDATA[<p>Hi,James,I found sth error in your parseURL method,if uses your method in IE,the &#8220;file&#8221; property will return a empty string like that:&#8221;http://www.jsparadise.cn:8080/index.html?id=123&amp;pages=4&#8243;.<br />
so I change the RegExp like that:<br />
&#8220;file: (a.pathname.match(/\/?([^\/?#]+)$/i) || [,''])[1]&#8220;,it will solve this problem. ^_^</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James</title>
		<link>http://james.padolsey.com/javascript/parsing-urls-with-the-dom/comment-page-1/#comment-10286</link>
		<dc:creator>James</dc:creator>
		<pubDate>Wed, 22 Apr 2009 22:22:11 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=572#comment-10286</guid>
		<description>Interesting! Thanks for the tests Paul! :)</description>
		<content:encoded><![CDATA[<p>Interesting! Thanks for the tests Paul! <img src='http://james.padolsey.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul Irish</title>
		<link>http://james.padolsey.com/javascript/parsing-urls-with-the-dom/comment-page-1/#comment-10285</link>
		<dc:creator>Paul Irish</dc:creator>
		<pubDate>Wed, 22 Apr 2009 22:01:57 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=572#comment-10285</guid>
		<description>I finally got around to benchmarking this against Steven&#039;s &lt;a href=&quot;http://blog.stevenlevithan.com/archives/parseuri&quot; rel=&quot;nofollow&quot;&gt;parseUri&lt;/a&gt;.

&lt;strong&gt;Test code:&lt;/strong&gt;
&lt;pre lang=&quot;javascript&quot;&gt;
var start = +new Date, x = 2000;
while(--x){
  parseURL(&#039;http://abc.com:8080/dir/index.html?id=255&amp;m=hello#top&#039;);
}
console.log(&#039;parseURL: &#039;,+new Date - start);


var start = +new Date, x = 2000;
while(--x){
  parseUri(&#039;http://abc.com:8080/dir/index.html?id=255&amp;m=hello#top&#039;);
}
console.log(&#039;parseUri: &#039;,+new Date - start);

&lt;/pre&gt;

&lt;strong&gt;Results&lt;/strong&gt;
Firefox 3:
parseURL: 541
parseUri: 157

IE 6:
parseURL: 781
parseUri: 312

Chrome 1:
parseURL: 498
parseUri: 242

So the regex is faster, but I&#039;m still quite fond of the DOM approach. :-]</description>
		<content:encoded><![CDATA[<p>I finally got around to benchmarking this against Steven&#8217;s <a href="http://blog.stevenlevithan.com/archives/parseuri">parseUri</a>.</p>
<p><strong>Test code:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span class="kw2">var</span> start <span class="sy0">=</span> <span class="sy0">+</span><span class="kw2">new</span> Date<span class="sy0">,</span> x <span class="sy0">=</span> <span class="nu0">2000</span><span class="sy0">;</span>
<span class="kw1">while</span><span class="br0">&#40;</span><span class="sy0">--</span>x<span class="br0">&#41;</span><span class="br0">&#123;</span>
  parseURL<span class="br0">&#40;</span><span class="st0">'http://abc.com:8080/dir/index.html?id=255&amp;amp;m=hello#top'</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
console.<span class="me1">log</span><span class="br0">&#40;</span><span class="st0">'parseURL: '</span><span class="sy0">,+</span><span class="kw2">new</span> Date <span class="sy0">-</span> start<span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
&nbsp;
<span class="kw2">var</span> start <span class="sy0">=</span> <span class="sy0">+</span><span class="kw2">new</span> Date<span class="sy0">,</span> x <span class="sy0">=</span> <span class="nu0">2000</span><span class="sy0">;</span>
<span class="kw1">while</span><span class="br0">&#40;</span><span class="sy0">--</span>x<span class="br0">&#41;</span><span class="br0">&#123;</span>
  parseUri<span class="br0">&#40;</span><span class="st0">'http://abc.com:8080/dir/index.html?id=255&amp;amp;m=hello#top'</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
console.<span class="me1">log</span><span class="br0">&#40;</span><span class="st0">'parseUri: '</span><span class="sy0">,+</span><span class="kw2">new</span> Date <span class="sy0">-</span> start<span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>

<p><strong>Results</strong><br />
Firefox 3:<br />
parseURL: 541<br />
parseUri: 157</p>
<p>IE 6:<br />
parseURL: 781<br />
parseUri: 312</p>
<p>Chrome 1:<br />
parseURL: 498<br />
parseUri: 242</p>
<p>So the regex is faster, but I&#8217;m still quite fond of the DOM approach. :-]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James</title>
		<link>http://james.padolsey.com/javascript/parsing-urls-with-the-dom/comment-page-1/#comment-6435</link>
		<dc:creator>James</dc:creator>
		<pubDate>Thu, 26 Feb 2009 07:53:11 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=572#comment-6435</guid>
		<description>Thanks for the comments. :)

Like almost everything I write about, this was just a bit of an experiment. Feature-wise it certainly does not match up to Steven&#039;s work. 

@Steven, thanks for the correction on the tp/tps thing. For my test I used a typical scenario - waiting to retrieve all the parts of a URL. It&#039;s worth mentioning that I didn&#039;t test against your original version; I tested against Mark&#039;s jQuery port which was very slow in comparison to my above attempt. Although, like you said, the results are invalidated because of the inherent differences of the returned results. 

@Mark, Oddly Steven&#039;s original version is faster than yours because it returns all the information as properties while yours requires each bit of info to be initiated as a method in order to retrieve results. Doing this is probably adding overhead.</description>
		<content:encoded><![CDATA[<p>Thanks for the comments. <img src='http://james.padolsey.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Like almost everything I write about, this was just a bit of an experiment. Feature-wise it certainly does not match up to Steven&#8217;s work. </p>
<p>@Steven, thanks for the correction on the tp/tps thing. For my test I used a typical scenario &#8211; waiting to retrieve all the parts of a URL. It&#8217;s worth mentioning that I didn&#8217;t test against your original version; I tested against Mark&#8217;s jQuery port which was very slow in comparison to my above attempt. Although, like you said, the results are invalidated because of the inherent differences of the returned results. </p>
<p>@Mark, Oddly Steven&#8217;s original version is faster than yours because it returns all the information as properties while yours requires each bit of info to be initiated as a method in order to retrieve results. Doing this is probably adding overhead.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sanbor</title>
		<link>http://james.padolsey.com/javascript/parsing-urls-with-the-dom/comment-page-1/#comment-6369</link>
		<dc:creator>Sanbor</dc:creator>
		<pubDate>Wed, 25 Feb 2009 18:22:11 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=572#comment-6369</guid>
		<description>You&#039;re a javascript rockstar ! :P</description>
		<content:encoded><![CDATA[<p>You&#8217;re a javascript rockstar ! <img src='http://james.padolsey.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steven L.</title>
		<link>http://james.padolsey.com/javascript/parsing-urls-with-the-dom/comment-page-1/#comment-6318</link>
		<dc:creator>Steven L.</dc:creator>
		<pubDate>Wed, 25 Feb 2009 05:01:12 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=572#comment-6318</guid>
		<description>@Mark Perkins, re: @Paul Irish&#039;s question, I suspect &quot;jQuery URL Parser&quot; adds performance overhead on top of parseUri, but in any case, I&#039;m interested in the actual test behind James&#039;s performance assertion. E.g., if the test is done in parseUri&#039;s loose parsing mode, that&#039;s apples to oranges because this function offers no &quot;loose&quot; mode, nor does it do any processing to extract user info from a URL, etc.  I expect using the DOM like this to be faster, regardless, but we&#039;re talking about the difference between two fast functions that are unlikely to ever present a real bottleneck.

I played around with this DOM-based approach a couple years ago based on a comment on my parseUri post, but I don&#039;t think this approach can offer all the same functionality (strict vs. loose parsing, all parts being optional, etc.) in comparable code length. Note that this function will incorrectly (IMO) return the protocol, host, port, and path of the page running the script if those segments are not included in the URI passed to the function (e.g., with parseURL(&quot;?q=v&quot;)).

@James Padolsey, the regex used for the &quot;relative&quot; property currently only works with protocols that end with &quot;tp&quot; (e.g., not &quot;https&quot;).</description>
		<content:encoded><![CDATA[<p>@Mark Perkins, re: @Paul Irish&#8217;s question, I suspect &#8220;jQuery URL Parser&#8221; adds performance overhead on top of parseUri, but in any case, I&#8217;m interested in the actual test behind James&#8217;s performance assertion. E.g., if the test is done in parseUri&#8217;s loose parsing mode, that&#8217;s apples to oranges because this function offers no &#8220;loose&#8221; mode, nor does it do any processing to extract user info from a URL, etc.  I expect using the DOM like this to be faster, regardless, but we&#8217;re talking about the difference between two fast functions that are unlikely to ever present a real bottleneck.</p>
<p>I played around with this DOM-based approach a couple years ago based on a comment on my parseUri post, but I don&#8217;t think this approach can offer all the same functionality (strict vs. loose parsing, all parts being optional, etc.) in comparable code length. Note that this function will incorrectly (IMO) return the protocol, host, port, and path of the page running the script if those segments are not included in the URI passed to the function (e.g., with parseURL(&#8220;?q=v&#8221;)).</p>
<p>@James Padolsey, the regex used for the &#8220;relative&#8221; property currently only works with protocols that end with &#8220;tp&#8221; (e.g., not &#8220;https&#8221;).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Elijah Grey</title>
		<link>http://james.padolsey.com/javascript/parsing-urls-with-the-dom/comment-page-1/#comment-6307</link>
		<dc:creator>Elijah Grey</dc:creator>
		<pubDate>Wed, 25 Feb 2009 02:25:47 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=572#comment-6307</guid>
		<description>location.host !== location.hostname (location.host includes any non-normal ports) You should replace line 11 with this:

&lt;pre lang=&quot;javascript&quot;&gt;
host: a.host,
hostname: a.hostname,
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>location.host !== location.hostname (location.host includes any non-normal ports) You should replace line 11 with this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">host<span class="sy0">:</span> a.<span class="me1">host</span><span class="sy0">,</span>
hostname<span class="sy0">:</span> a.<span class="me1">hostname</span><span class="sy0">,</span></pre></div></div>

]]></content:encoded>
	</item>
	<item>
		<title>By: Mark Perkins</title>
		<link>http://james.padolsey.com/javascript/parsing-urls-with-the-dom/comment-page-1/#comment-6244</link>
		<dc:creator>Mark Perkins</dc:creator>
		<pubDate>Tue, 24 Feb 2009 10:39:17 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=572#comment-6244</guid>
		<description>James -

Great work. Never occurred to me that you could use the parse a URL in this way, and I have to say it is a much neater implementation (and faster too, as you say!) than my plugin. Good stuff! Looks like it&#039;s back to using someone elses code for my url parsing :-)

@Paul Irish - I would imagine that the speed difference would be about 12 times, as Stephens parseUri function forms the core of my jQuery URL Parser plugin that James&#039; comparison references.</description>
		<content:encoded><![CDATA[<p>James -</p>
<p>Great work. Never occurred to me that you could use the parse a URL in this way, and I have to say it is a much neater implementation (and faster too, as you say!) than my plugin. Good stuff! Looks like it&#8217;s back to using someone elses code for my url parsing <img src='http://james.padolsey.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>@Paul Irish &#8211; I would imagine that the speed difference would be about 12 times, as Stephens parseUri function forms the core of my jQuery URL Parser plugin that James&#8217; comparison references.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James</title>
		<link>http://james.padolsey.com/javascript/parsing-urls-with-the-dom/comment-page-1/#comment-6107</link>
		<dc:creator>James</dc:creator>
		<pubDate>Sun, 22 Feb 2009 20:38:07 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=572#comment-6107</guid>
		<description>Hey, now that is a really cool use of the DOM API... awesome work.</description>
		<content:encoded><![CDATA[<p>Hey, now that is a really cool use of the DOM API&#8230; awesome work.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: zhys9</title>
		<link>http://james.padolsey.com/javascript/parsing-urls-with-the-dom/comment-page-1/#comment-6075</link>
		<dc:creator>zhys9</dc:creator>
		<pubDate>Sun, 22 Feb 2009 10:57:40 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=572#comment-6075</guid>
		<description>cool
reprint url &lt;a href=&quot;http://zhys9.com/blog/?p=104&quot; rel=&quot;nofollow&quot;&gt;http://zhys9.com/blog/?p=104&lt;/a&gt;</description>
		<content:encoded><![CDATA[<p>cool<br />
reprint url <a href="http://zhys9.com/blog/?p=104">http://zhys9.com/blog/?p=104</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>

