Support modulePreload when generating html #1079
Open
+120
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 newdynamic_prefetch
field to theResourcesInjectorOptions
struct that is a vector ofDynamicPrefetchResource
objects.In the
ResourcesInjector
class, I added a newinject_dynamic_prefetch
method that injects a<link>
element withrel="prefetch"
for each dynamic prefetch resource. I also added anonload
event listener to the<link>
element that will prefetch the dynamic imports of the corresponding module when the<link>
element has finished loading. Theonload
event listener uses thegetDynamicModuleResourcesMap
method from theFARM_MODULE_SYSTEM
to get the dynamic imports of the corresponding module.Finally, I modified the
visit_mut_element
method to call theinject_dynamic_prefetch
method in addition to theinject_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.