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

Avoid FEAAS Stylesheets parsing multiple times #1320

Merged
merged 11 commits into from
Feb 21, 2023

Conversation

Inviz
Copy link
Collaborator

@Inviz Inviz commented Feb 2, 2023

Description / Motivation

FEAAS Components require stylesheet of their libraries to run. Multiple components from the same library can be used on a single page. To ensure that stylesheets start loading as soon as possible, I suggested including stylesheet tag for each component. However with this approach even if stylesheet is loaded once (browser deduplicates requests) it's parsed and initialized multiple times (which can be seen in chrome dev console, having css rules multiplied).

The solution to this problem is to use rel="preload" which will initiate loading during page parsing, so by the time JS is loaded, the static files are already pre-fetched. We also do it for preloading HTML and JS. Combined with SSG, this makes the files load as soon as possible, and still on demand.

Testing Details

The result can be seen on any environment using feaas component.

Example of stylesheet preloading with cold cache:
1 request: Preloading
2 request: Fetching, 0 bytes - served from cache
3 request: background HEAD request, checks if the cache needs to be busted (feaas does stale-while-revalidate-hot-reload strategy for handling cache). This head request is not absolutely necessary conceptually for the case of cold cache, but it's lightweight (only headers) and it's a trade-off of preloading the static file.

MicrosoftTeams-image (10)

Example with hot cache
1 request: 5ms - served from disk cache
2 request: 4ms - served from disk cache
3 request: background HEAD request, checks if the cache needs to be busted. Important, as it's the only way to validate the freshness of cached file with immutable policy

Screen Shot 2023-02-03 at 00 32 51

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Inviz and others added 3 commits February 3, 2023 00:25
FEAAS Components require stylesheet of their libraries to run. Multiple components from the same library can be used on a single page. To ensure that stylesheets start loading as soon as possible, I suggested including stylesheet tag for each component. However with this approach even if stylesheet is loaded once (browser deduplicates requests) it's parsed and initialized multiple times (which can be seen in chrome dev console, having css rules multiplied). 

The solution to this problem is to use `rel="preload"` which will initiate loading during page parsing, so by the time JS is loaded, the static files are already pre-fetched. We also do it for preloading HTML and JS. Combined with SSG, this makes the files load as soon as possible, and still on demand.
Self-close the stylesheet
@ambrauer ambrauer marked this pull request as draft February 7, 2023 15:04
@Inviz Inviz force-pushed the feature/avoid-feaas-stylesheet-reparsing branch from 1ca760a to f8d7023 Compare February 17, 2023 04:58
@Inviz Inviz marked this pull request as ready for review February 17, 2023 05:07
@Inviz
Copy link
Collaborator Author

Inviz commented Feb 17, 2023

@ambrauer I think this is ready for review. It should be non-breaking as it just changes type of preloading we're doing.

@ambrauer ambrauer changed the title Not ready: Avoid FEAAS Stylesheets parsing multiple times Avoid FEAAS Stylesheets parsing multiple times Feb 17, 2023
Copy link
Contributor

@ambrauer ambrauer left a comment

Choose a reason for hiding this comment

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

@Inviz Just one question, otherwise looks good to me

@ambrauer ambrauer merged commit 6410156 into dev Feb 21, 2023
@ambrauer ambrauer deleted the feature/avoid-feaas-stylesheet-reparsing branch February 21, 2023 14:58
@Inviz
Copy link
Collaborator Author

Inviz commented Feb 21, 2023

thanks Adam

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.

None yet

2 participants