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

Support modulePreload when generating html #1079

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

Conversation

aniketkumar7
Copy link

Sure, here's the updated description with "I" instead of "We":

This pull request addresses the issue of prefetching resources for dynamic imports in Farm. The current implementation of prefetching in Farm only handles static resources, but dynamic imports require a more sophisticated approach to ensure that resources are prefetched at the correct time.

To solve this issue, I introduced a new DynamicPrefetchResource struct that represents a resource that should be prefetched when its corresponding module is loaded. I also added a new dynamic_prefetch field to the ResourcesInjectorOptions struct that is a vector of DynamicPrefetchResource objects.

In the ResourcesInjector class, I added a new inject_dynamic_prefetch method that injects a <link> element with rel="prefetch" for each dynamic prefetch resource. I also added an onload event listener to the <link> element that will prefetch the dynamic imports of the corresponding module when the <link> element has finished loading. The onload event listener uses the getDynamicModuleResourcesMap method from the FARM_MODULE_SYSTEM to get the dynamic imports of the corresponding module.

Finally, I modified the visit_mut_element method to call the inject_dynamic_prefetch method in addition to the inject_preload_and_prefetch method when processing the <head> element.

With these changes, Farm can now prefetch resources for dynamic imports at the correct time, improving the performance of applications that rely on dynamic imports.

Copy link

changeset-bot bot commented Mar 27, 2024

⚠️ No Changeset found

Latest commit: ec4ff0d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@callqh callqh requested a review from wre232114 March 27, 2024 03:45
@wre232114
Copy link
Member

Could you add a example html-preload with a e2e.test.ts under examples to test it and make sure it works

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.

2 participants