GoogleChromeLabs / quicklink

⚡️Faster subsequent page-loads by prefetching in-viewport links during idle time
https://getquick.link
Apache License 2.0
10.97k stars 403 forks source link

Update request for "quicklink" library to fix CORS errors #419

Open giorgiopellegrino opened 2 months ago

giorgiopellegrino commented 2 months ago

Hi @gilbertococchi @addyosmani ,

I am contacting you to ask for an update of the “quicklink” library in order to solve a problem related to CORS errors during resource prefetching.

Specifically, I would like to have the attribute “crossorigin=”anonymous“” added while the prefetch link element is added to the DOM in the “src/prefetch.mjs” file. This is the updated code I would like to implement:

image

The reason for this change is to ensure that prefetched resources are not treated as opaque resources but as cors resources, thus avoiding possible CORS errors when they are retrieved from the cache.

Here is an example of the error that currently occurs when a prefetched resource is called from the cache:

image

Alternatively, one solution might be to allow the user to choose whether to add the “cross-origin” attribute using the API. An example of a call could be: quicklink.prefetch("URLResource", false, {crossorigin:"anonymous"});

Thank you for your attention and timely resolution of this issue.

Sincerely yours,

Giorgio Pellegrino.

gilbertococchi commented 2 months ago

Hi Giorgio, thanks for opening this issue.

It seems like you would like to personalize the crossorigin attribute of the Fetch or Link=Prefetch tags generated by QuickLink.

Would you be able to open a PR with the suggested code change? I would be happy to review and provide some suggestions.

Currently the quicklink.prefetch method only support the boolean config isPriority.

It would be required to switch to an option method as you suggested and that may fall as a breaking change.

giorgiopellegrino commented 2 months ago

Dear @gilbertococchi @addyosmani ,

I would like to inform you that I have processed a pull request (https://github.com/GoogleChromeLabs/quicklink/pull/423).

I would kindly appreciate instructions on any further actions necessary to ensure the validity of the above request.

Thank you.

Giorgio