Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Draft
- Cornerstone performance optimizations: blocking scripts delaying DomContentLoaded. [#2158](https://github.com/bigcommerce/cornerstone/pull/2158)
- Cornerstone performance optimizations: remove unused fonts. [#2176](https://github.com/bigcommerce/cornerstone/pull/2176)
- Update stencil-utils package. [#2157](https://github.com/bigcommerce/cornerstone/pull/2157)

Expand Down
13 changes: 13 additions & 0 deletions assets/js/theme/common/font.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const WebFont = require('webfontloader');

const linkEl = document.querySelector('link[href*="https://fonts.googleapis.com/css"]');
const fontUrl = linkEl.getAttribute('href');
const regexFontsCollection = /family=([^&]*)/gm;
const families = regexFontsCollection.exec(fontUrl)[1].replace(/\+/gm, ' ').split('|');

WebFont.load({
custom: {
families,
},
classes: false,
});
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"slick-carousel": "^1.8.1",
"svg-injector": "^1.1.3",
"sweetalert2": "^9.17.2",
"webfontloader": "^1.6.28",
"whatwg-fetch": "^3.6.1"
},
"devDependencies": {
Expand Down
26 changes: 12 additions & 14 deletions templates/layout/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,12 @@
window.lazySizesConfig.loadMode = 1;
</script>
<script async src="{{cdn 'assets/dist/theme-bundle.head_async.js'}}"></script>

{{getFontsCollection font-display='block'}}

<link rel="preload" href="{{cdn 'assets/dist/theme-bundle.font.js'}}" as="script">
<script async src="{{cdn 'assets/dist/theme-bundle.font.js'}}"></script>

<script src="https://ajax.googleapis.com/ajax/libs/webfont/1.6.26/webfont.js"></script>

<script>
WebFont.load({
custom: {
families: ['Karla', 'Roboto', 'Source Sans Pro']
},
classes: false
});
</script>

{{ getFontsCollection }}
{{{stylesheet '/assets/css/theme.css'}}}

{{{head.scripts}}}
Expand All @@ -58,6 +51,9 @@
{{~inject 'carouselArrowAndDotAriaLabel' (lang 'carousel.arrow_and_dot_aria_label')}}
{{~inject 'carouselActiveDotAriaLabel' (lang 'carousel.active_dot_aria_label')}}
{{~inject 'carouselContentAnnounceMessage' (lang 'carousel.content_announce_message')}}

{{!-- Get this loading ASAP --}}
<link rel="preload" href="{{cdn 'assets/dist/theme-bundle.main.js'}}" as="script">
</head>
<body>
<svg data-src="{{cdn 'img/icon-sprite.svg'}}" class="icons-svg-sprite"></svg>
Expand All @@ -67,11 +63,13 @@
{{> components/common/footer }}

<script>window.__webpack_public_path__ = "{{cdn 'assets/dist/'}}";</script>
<script src="{{cdn 'assets/dist/theme-bundle.main.js'}}"></script>
<script>
{{!-- Exported in app.js --}}
window.stencilBootstrap("{{page_type}}", {{jsContext}}).load();
function onThemeBundleMain() {
window.stencilBootstrap("{{page_type}}", {{jsContext}}).load();
}
</script>
<script async defer src="{{cdn 'assets/dist/theme-bundle.main.js'}}" onload="onThemeBundleMain()"></script>

{{{footer.scripts}}}
</body>
Expand Down
1 change: 1 addition & 0 deletions webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = {
entry: {
main: './assets/js/app.js',
head_async: ['lazysizes'],
font: './assets/js/theme/common/font.js',
polyfills: './assets/js/polyfills.js',
},
module: {
Expand Down