Combining Whitelist & Same-Origin
Closed this issue · 3 comments
Hi!
Thank you very much for your script, I like the way you designed your library. It's really simple to understand, and it seems to do the job well, at least from my first tests! 🤗
I just want you to know another use case that I think might be useful: combining data-tachyon-same-origin
and data-tachyon-whitelist
. This would allow the user to preload their website links and other links that a developer has marked in the allow list. For example, to preload links from:
- https://github.com/ (current website)
- and https://raw.githubusercontent.com/ (only marked links)
Rest assured that I do not want you to implement this use case if you think it's not worth it for a lot of users. 😅 I had already planned to use a slightly modified version of your script for my peculiar use case. 😉
Thanks again!
~ Benjamin
if ((node.tagName === 'A' && node.href) && (('tachyon' in node.dataset === whitelistEnabled) || (!sameOriginOnly || node.origin === window.location.origin))) {
['mouseover', 'mouseout', 'touchstart', 'touchend'].forEach((eventName) => node.addEventListener(eventName, toggleLinkTag, { passive: true }));
}
This is a good idea and seems to be somewhat of an oversight on my part. I'll look into it more sometime this week; thanks for pointing this out and glad you're getting some use out of the project!
I think the way I'm likely to implement this is by making data-tachyon-same-origin
a subset of the whitelist, i.e. automatically enabling the whitelist with data-tachyon-same-origin
. I'm not sure if this is exactly what you're describing, but this seems to make the most sense to me:
- Adding
data-tachyon-same-origin
to the body tag will behave the same way asdata-tachyon-whitelist
BUT will automatically add same-origin links to the whitelist. - While
data-tachyon-same-origin
is on the body tag, addingdata-tachyon
to different-origin anchor tags will add them to the whitelist, just like withdata-tachyon-whitelist
Your thoughts? I don't actually use data-tachyon-same-origin
in production, so some input would be great.
Please see the documentation for how to utilize the changes. Thanks for bringing this to my attention!