Ticket #16 (closed enhancement: wontfix)

Opened 2 years ago

Last modified 2 years ago

start href attribute with '#'

Reported by: Balazs Endresz Owned by: nathanhammond
Priority: major Milestone: Version 1.0
Component: jQuery Plugin Version: 0.9
Keywords: Cc:
Blocking: Blocked By:

Description

Hi,
I've just implemented JSSM and it's VERY nice. I've only had one problem: if you open a link in a new tab only some textual content is loaded as I'm just loading some text to some part of the page. So at the end of your plugin I replaced

href=this.href
with
href=this.href.replace(/[^\/]*#/, '')

Now you can start each href with a #. This enables you to open any link in a new tab and JSSM can handle things in that tab as well (with the same url, only the hash changed), instead of directly loading the link (like now, without #).

Attachments

jssm_16.zip (34.5 kB) - added by Balazs Endresz 2 years ago.

Change History

  Changed 2 years ago by nathanhammond

Balazs, I've tried playing with the change you suggest but I think I'm misunderstanding your use case. Can you post an example of what you're trying to accomplish that I can have a look at? Thanks!

Changed 2 years ago by Balazs Endresz

in reply to: ↑ description   Changed 2 years ago by nathanhammond

  • status changed from new to closed
  • resolution set to wontfix

Hey Balasz,
I don't think I'm going to include this change in the core. The reason I don't want to include it is that, in the optimal approach, the file "1.html" would recognize that it isn't being requested by XHR (jQuery sets a request header: xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");) and it would return itself within the full context of "index.html". This has numerous advantages for accessibility, SEO, and performance:

  • It requires no JavaScript on the client side to work correctly.
  • All pages become indexable in the context of the wrapper content.
  • It would prevent an XHR Get on first page load.

Your modification will work in the scenario you've got but it also has one big drawback: prepending with a '#' requires the browser to have JavaScript to access the content.

To reach a middle ground between your approach and my approach I'd suggest having all of the URLs be relative only (not prepended with '#'), and modifying the jQuery plugin segment to add in:

if (this.href) {
	this.setAttribute('href', '#'+this.getAttribute('href'));
}

After this line:

return this.each(function (i) ...

This at least won't lock out a user if they don't have JavaScript ... but it also has problems with links that are being added in dynamically in IE--any link added to the DOM with innerHTML will automatically have only a fully-resolved path (http://www.example.com/) and JSSM will fail if passed a hash like: #http://www.example.com. The brief lines of code above can be modified to address that scenario though, and reset the href on those links appropriately (you can even use JSSM's getRelativePath function).

I don't know exactly what you're trying to accomplish with the regular expression you're adding:

href = this.href.replace(/[^\/]*#/, '');

But in my approach for a speed increase you could swap that for:

href = this.href.substr(this.href.indexOf('#'));

I will document the suggestion I'm making here so that this use case is still easily addressable with JSSM.

  Changed 2 years ago by Balazs Endresz

Ok, I agree with you, it would really make the content quite hard for search engines to index. And by checking the "X-Requested-With" header you can still send only partial content to cut file size if that matters. But in other cases google will still see the whole page and no xhr on first page load.

Later I've also figured it out to add the # with javascript; with the regex I was assuming a fully-resolved path (it looked like that on the console :) but it's unnecessary, true. But I didn't know about dinamically added links, thanks for pointing out.

Anyway, you're right, it's just good as it is :)
Thanks!

Note: See TracTickets for help on using tickets.