Skip to content

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

Closed
SkyZeroZx wants to merge 1 commit into
angular:mainfrom
SkyZeroZx:add-fetch-performance
Closed

SkyZeroZx wants to merge 1 commit into
angular:mainfrom
SkyZeroZx:add-fetch-performance

Conversation

@SkyZeroZx

@SkyZeroZx SkyZeroZx commented May 30, 2025 •

Copy link
Copy Markdown
Contributor

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
Comment thread packages/common/http/src/request.ts Resolved
@pullapprove
pullapprove Bot requested review from alxhub, kirjs and thePunderWoman June 12, 2025 00:42

@thePunderWoman thePunderWoman left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor Author

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

@JeanMeche

Copy link
Copy Markdown
Member

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

@SkyZeroZx

Copy link
Copy Markdown
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 140741

@JeanMeche

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

@JeanMeche I already updated it

@SkyZeroZx

Copy link
Copy Markdown
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

@kirjs kirjs left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
@angular-automatic-lock-bot

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Jul 29, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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