Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent if link is URL fragment #49

Closed
wants to merge 1 commit into from

Conversation

arkist
Copy link

@arkist arkist commented Dec 15, 2018

Currently, quicklink trying prefetch even if link is just plain URL fragment.

<link rel="prefetch" href="http://localhost:8080/demos/basic.html#3rdScreen">

@lukeed
Copy link
Contributor

lukeed commented Dec 16, 2018

My gut reaction is that this should live within user ignores 🤔 While it makes sense in the general case, there'd be no way around this if your site's client was using the /#/ (or similar) routing convention. For example:

// localhost:8000/#/hello
location.pathname = '/';
location.hash = '#/hello';

// localhost:8000/#/world
location.pathname = '/';
location.hash = '#/world';

Here, the hostname & pathnames are identical, but the unique hashes can actually be different pages – whether they're rendered dynamically thru Angular/Vue/Preact/etc. In this case, external prefetching is & should still be enabled.

Including this logic into the core of quicklink would block this pattern.

@arkist
Copy link
Author

arkist commented Dec 16, 2018

@lukeed Oh I forgot about that, thanks! 😄
but isn't hash works on just client-side only?
I mean, are xhr/link[rel=prefetch] can handle hash based route?

@addyosmani
Copy link
Collaborator

addyosmani commented Dec 16, 2018

I'm tempted to agree with @lukeed that control over URL fragment behavior is something we should defer to the new ignores feature (in latest stable) 😄 It's possible to filter out any links in a page with fragments and only prefetch those that don't have them if that's the desired outcome.

My preference here would be that we document in the README how to use ignores to achieve the above, but not make this change to core.

@arkist if you get a chance, would be awesome if you could try out using ignores for this use case and let us know if there's anything missing from it for your needs.

@addyosmani addyosmani added the enhancement New feature or request label Dec 16, 2018
@arkist
Copy link
Author

arkist commented Dec 16, 2018

@addyosmani Okay I'll try later 👌 thanks! 😄

@lukeed
Copy link
Contributor

lukeed commented Dec 17, 2018

Hey @arkist, so you're right in that quicklink won't prefetch those as different pages. However, this is also true of any links with fragments / hashes. This is because only the pathname value is significant & is all that's fetched.

"localhost:8000/#/hello"
//=> fetched as "localhost:8080"

"localhost:8000/#/world"
//=> fetched as "localhost:8080"

"localhost:8000#hello"
//=> fetched as "localhost:8000"

"localhost:8000/demos/basic.html#3rdScreen"
//=> fetched as "localhost:8000/demos/basic.html"

"localhost:8000/demos/basic.html#2ndScreen"
//=> fetched as "localhost:8000/demos/basic.html"

That said, I'm still not sure that this logic should belong within the core handler, as it would definitely also block querystring differences; eg: /news?now=123 vs /news?now=456 – those should intentionally be difference & not be blocked nor prevented.

@arkist
Copy link
Author

arkist commented Dec 17, 2018

@lukeed woah, you're right 🤯 as you explained, my code could be a problem in that kind of querystring case.
thank you again!

addyosmani added a commit that referenced this pull request Dec 17, 2018
docs(README): add URL fragments note about ignores (#52, #49)
@arkist
Copy link
Author

arkist commented Dec 17, 2018

my last thought about treat URL fragment is /a to /b#step2, /b#step3 case.
in that case you should check pathname not just check hash included.
also, should store preFetched url without hash maybe 🤔

@arkist arkist closed this Dec 17, 2018
@arkist
Copy link
Author

arkist commented Dec 17, 2018

Oh, I pressed the 'close PR' button by mistake 😅
(but it's okay, isn't it? 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants