8000 feat(http): Add support for fetch request cache and priority options by SkyZeroZx · Pull Request #61766 · angular/angular · GitHub
[go: up one dir, main page]

Skip to content

feat(http): Add support for fetch request cache and priority options #61766

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

Closed
wants to merge 1 commit into from

Conversation

SkyZeroZx
Copy link
Contributor
@SkyZeroZx SkyZeroZx commented May 30, 2025

This commit adds support for the Fetch API's cache and priority options when using HttpClient with the withFetch provider.

The change includes:

  • Added cache and priority to the HttpRequestInit interface
  • Modified FetchBackend to pass the options
  • Added unit tests to validate behavior

Motivation / Use Cases

The cache and priority options are particularly useful for:

  • Controlling how HTTP requests are cached (cache: 'no-store', 'reload', etc.)
  • Suggesting the relative priority of resource loading to the browser (priority: 'high', 'low', 'auto')
  • Improving performance metrics (e.g., LCP) by prioritizing critical assets
  • Reducing unnecessary network traffic for cached resources

Proposed Solution

  • Add cache and priority to the HttpRequestInit interface
  • Implement property handling in the HttpRequest class
  • Pass the options through FetchBackend to the native Fetch API
  • Maintain full backward compatibility

Examples of New Usage

// GET request with cache and priority
http.get('/assets/hero-image.jpg', {
  cache: 'force-cache',
  priority: 'high'
}).subscribe();

@pullapprove pullapprove bot requested a review from kirjs May 30, 2025 02:17
@angular-robot angular-robot bot added detected: feature PR contains a feature commit area: common/http Issues related to HTTP and HTTP Client labels May 30, 2025
@ngbot ngbot bot added this to the Backlog milestone May 30, 2025
@SkyZeroZx SkyZeroZx force-pushed the add-fetch-performance branch 2 times, most recently from ef37d29 to 4a18afd Compare May 30, 2025 04:26
@pullapprove pullapprove bot requested review from alxhub, kirjs and thePunderWoman June 12, 2025 00:42
Copy link
Contributor
@thePunderWoman thePunderWoman left a comment

Choose a reason for hiding this comment

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

LGTM

reviewed-for: fw-general, public-api

@pullapprove pullapprove bot requested a review from crisbeto June 12, 2025 08:47
@SkyZeroZx
Copy link
Contributor Author

@kirjs It is possible to run the lint again, it seems to have been a sporadic error.

@JeanMeche
Copy link
Member

@SkyZeroZx The linting error is correct, you need to reformat the file.

@SkyZeroZx
Copy link
Contributor Author

@SkyZeroZx The linting error is correct, you need to reformat the file.

@JeanMeche
It's a bit strange because I haven't touched the file you're referring to in "packages/core/src/render3/component.ts" where the pipeline shows the error.
The changes are associated with the common http module.
Just in case, running the commands locally on my branch doesn't show any changes I can upload as fixups.
I ran "yarn tslint" and "yarn lint." Maybe I'm missing something?

Screenshot error pipeline
image

Screenshot local branch
Captura de pantalla 2025-06-18 14074
8000
1

@JeanMeche
Copy link
Member

Could you update your local main branch and try rebasing ?
The file is indeed not correctly formatted but its untouched on your PR.

@JeanMeche
Copy link
Member

We don't accept merge commit in the PR we merge, we'll need a rebase instead.

@SkyZeroZx SkyZeroZx force-pushed the add-fetch-performance branch from db7dfeb to 1c012be Compare June 18, 2025 19:38
@SkyZeroZx
Copy link
Contributor Author

@JeanMeche I already updated it

@SkyZeroZx
Copy link
Contributor Author

@JeanMeche The linter has already been fixed, you can re-run what is failing this time if it is something from the unstable adev tests

Copy link
Contributor
@kirjs kirjs left a comment

Choose a reason for hiding this comment

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

Reviewed-for: public-api

@thePunderWoman thePunderWoman added action: merge The PR is ready for merge by the caretaker target: minor This PR is targeted for the next minor release labels Jun 24, 2025
Enhances Angular HttpClient requests with Fetch API cache and priority options to optimize loading and performance.
@thePunderWoman
Copy link
Contributor

This PR was merged into the repository by commit 9791ab1.

The changes were merged into the following branches: main

@SkyZeroZx SkyZeroZx deleted the add-fetch-performance branch June 26, 2025 01:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action: merge The PR is ready for merge by the caretaker area: common/http Issues related to HTTP and HTTP Client detected: feature PR contains a feature commit target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0