You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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 [[...path]].tsx
export const getStaticProps: GetStaticProps = async (context) => {
const props: SitecorePageProps = await sitecorePagePropsFactory.create(context)
const contentStylesLink = getContentStylesheetLink(
props.layoutData,
config.sitecoreEdgeContextId,
config.sitecoreEdgeUrl,
)
if (contentStylesLink?.href) {
props.contentStyles = await fetch(contentStylesLink.href)
.then((response) => response.text())
.catch((_e) => {
//TODO add logging
})
}
return {
props,
// Next.js will attempt to re-generate the page:
// - When a request comes in
// - At most once every 5 minutes
revalidate: 300, // In seconds
notFound: props.notFound, // Returns custom 404 page with a status code of 404 when true
}
}
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: