riganti / dotvvm

Open source MVVM framework for Web Apps
https://www.dotvvm.com
Apache License 2.0
751 stars 97 forks source link

Add support for priority hints using `fetchpriority` on JS and CSS resources #1482

Open acizmarik opened 2 years ago

acizmarik commented 2 years ago

This is a feature requested by BusinessPack team.

The main purpose is to provide more granular control over how are resources actually loaded. As such, if used correctly, this could provide better loading times and thus better user experience.

New API IMO this can be either implemented by adding new overloads to DotVVM.Framework.ResourceManagement.ResourceRepositoryExtensions or by adding new optional parameters to existing methods (although this would need to wait for next major release).

Implementation / Rendering It seems like there are only three possible values for fetchpriority attribute: low, high and auto. The value auto can be omitted (it is the default value) and therefore we need to render only low and high values.

Limitations As of writing this issue, it seems like only Chromium-based browsers support this. https://caniuse.com/mdn-html_elements_img_fetchpriority.

exyi commented 2 years ago

Adding an optional parameter is source compatible change, so it'd be fine to do in 4.1 release. But I don't think that many people will want to use it, so we could only add new property to the StylesheetResource class.

As of writing this issue, it seems like only Chromium-based browsers support this. https://caniuse.com/mdn-html_elements_img_fetchpriority.

It's not even standardized. The major use case of this are images, IMO, and there is nothing stopping you from using it. I'd prefer to wait for standardization when it comes to resources, unless someone comes with a benchmark where it helps significantly.

acizmarik commented 2 years ago

You are right, I would probably wait for the standardization as well. Also it is pretty clear that it is possible to render additional attributes using current API.

Once and if this gets standardized, we can reconsider whether to add helper methods / parameters for this. Unless, of course someone comes with a good reason why this should be added sooner.

exyi commented 1 month ago

This now seems to be standardized, and we can therefore safely add support. Currently is implemented by Safari and Chromium, and since it's just a loading hint there is no need to wait for full support across browsers.