-
Notifications
You must be signed in to change notification settings - Fork 276
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
Sitecore JSS adding blocking JS/CSS to page, hurting performance. #1991
Comments
@chrissnyder2337 thanks for raising this! Can you elaborate on your proposal with next/script please? As far as I know it only applies to scripts, not styles. The styles themselves are needed for SXA components, the page can look unfinished until they are loaded. The styles can be configured in Pages and will be used on live site. However, these styles shouldn't be loading if SXA styles are not used on the page. |
Hi we ended up injecting css directly to html to mitigate this issue. First fetch css in getStaticProps in
and then pass it as a prop to Layout component. and in
This makes html bigger however it has lower impact on performance than waiting for response |
@gregorjan This is a great approach. |
@gregorjan I think your solution would also address the following message I see in my console: Do not add stylesheets using next/head (see <link rel="stylesheet"> tag with href="https://edge-platform.sitecorecloud.io/v1/files/pages/styles/content-styles.css?sitecoreContextId=XXXXXXXXXXXX"). Use Document instead.
See more info here: https://nextjs.org/docs/messages/no-stylesheets-in-head-component |
Describe the Bug
I am auditing the performance of our frontend XM Cloud application (built using Next.js). We found that sitecore is adding blocking third-party JS/CSS, and not following Next.js’s best practices for including scripts/stylesheets. Specify
https://edge-platform.sitecorecloud.io/v1/files/pages/styles/content-styles.css?sitecoreContextId=XXXXXXXXXX
I have narrowed it down to the following code that is in
Layout.tsx
:Is it possible to include these in a non-blocking way? In my case this would result in a potential savings of almost a second.
To Reproduce
Run a lighthouse test on any page and note that the
content-styles.css
is reported as render blocking.Expected Behavior
The js/css added by sitecore's JSS SDK is not loaded in a blocking manner or in a way that does not negatively impact the page performance.
Possible Fix
Possibly load this using next/script with a non-blocking strategy.
Provide environment information
The text was updated successfully, but these errors were encountered: