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

add crossorigin attribute to prefetch method #423

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

giorgiopellegrino
Copy link

Hi. I added a new boolean parameter to the prefetch(url, isPriority, isCrossorigin) method.

When isCrossorigin is true, XHR calls will occur with mode: “cors”, and prefetch will add the crossorigin=“anonymous” attribute to the link element.
On the other hand, if isCorssorigin is false (default value), XHR calls will occur with credentials: “include”, and the prefetch will add the crossorigin=“use-credentials” attribute to the link element.

I hope this feature will be useful as well as to me to the whole community.
Thank you!

Giorgio

Copy link

google-cla bot commented May 9, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@XhmikosR
Copy link
Collaborator

@giorgiopellegrino please make sure everything is green locally and add a new test case too.

@giorgiopellegrino
Copy link
Author

Sorry, I forgot to run the npm run eslint-fix command and run the automatic tests.
I entered the JsDOCs and renamed the parameter from isCrossorigin to onlySameOrigin.
Therefore, using the API prefetch(url, isPriority, onlySameOrigin) will remain unchanged from before. However, if the last parameter is set to true as follows: prefetch(url, false, true), then XHR calls will be made with “include” credentials, and the prefetch will add the crossorigin=“use-credentials” attribute to the link element.

src/index.mjs Outdated Show resolved Hide resolved
@giorgiopellegrino giorgiopellegrino changed the title add isCrossorigin attribute to prefetch method add crossorigin attribute to prefetch method May 10, 2024
@giorgiopellegrino
Copy link
Author

I decided to simplify my feature by adding only the boolean parameter addCrossorigin to the prefetch(url, isPriority, addCrossorigin) method. When set to true, this parameter adds the crossorigin=“anonymous” attribute to the prefetch link.
Thank you.
Giorgio

.size-limit.json Outdated
@@ -19,4 +19,4 @@
"limit": "2 kB",
"gzip": true
}
]
]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are still unrelated changes, please revert all of them

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I undid the changes in the .size-limit.json file and changed the addCrossorigin parameter from a boolean to a “crossorigin” string, so as to reduce the space during minification, as the user will be entering the value of the property.
Thank you.
Giorgio

@giorgiopellegrino
Copy link
Author

Dear @XhmikosR ,

I would like to inform you that I recently performed a pull procedure from the main branch in order to keep the xmr/prefetch-crossorigin branch aligned with the same main branch.

I would appreciate any instructions regarding the next steps to be taken or if it is necessary to wait for certain developments before proceeding with merging my branch on the main branch, so to approve the PR.

I thank you in advance for the valuable information you would like to share.

Sincerely, Giorgio

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

Successfully merging this pull request may close these issues.

None yet

2 participants