Skip to content

Commit

Permalink
fix: turn off preload tag option by default (#86)
Browse files Browse the repository at this point in the history
This commit turns off preload tag generation for
Google Fonts by default because:
  - generally preconnect tags should be sufficient
  - adding preloads as well runs the risk of resource
    contention with more critical resources
  - preloads don't take into account font unicode
    ranges, which could be problematic for i18n

See more here: https://web.dev/font-best-practices/#avoid-using-preload-to-load-fonts
  • Loading branch information
kara committed Jun 9, 2022
1 parent bb8c6f2 commit fa4d4e0
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/module.ts
Expand Up @@ -26,7 +26,7 @@ const nuxtModule: Module<ModuleOptions> = function (moduleOptions) {
text: null,
prefetch: true,
preconnect: true,
preload: true,
preload: false,
useStylesheet: false,
download: false,
base64: false,
Expand Down
4 changes: 2 additions & 2 deletions test/basic.test.ts
Expand Up @@ -21,9 +21,9 @@ describe('basic', () => {
expect(body).toContain('<link data-n-head="ssr" data-hid="gf-origin-preconnect" rel="preconnect" href="https://fonts.googleapis.com/">')
})

test('has preload link', async () => {
test('does not have preload link by default', async () => {
const { body } = await get('/')
expect(body).toContain('<link data-n-head="ssr" data-hid="gf-preload" rel="preload" as="style" href="https://fonts.googleapis.com/css2?family=Roboto&amp;family=Lato">')
expect(body).not.toContain('<link data-n-head="ssr" data-hid="gf-preload" rel="preload" as="style" href="https://fonts.googleapis.com/css2?family=Roboto&amp;family=Lato">')
})

test('no has stylesheet link', async () => {
Expand Down
3 changes: 2 additions & 1 deletion test/fixture/use-stylesheet/nuxt.config.js
Expand Up @@ -12,6 +12,7 @@ export default {
families: {
Roboto: true
},
useStylesheet: true
useStylesheet: true,
preload: true
}
}
2 changes: 1 addition & 1 deletion test/use-stylesheet.test.ts
Expand Up @@ -16,7 +16,7 @@ describe('use stylesheet', () => {
expect(body).toContain('<link data-n-head="ssr" data-hid="gf-preconnect" rel="preconnect" href="https://fonts.gstatic.com/" crossorigin="">')
})

test('has preload link', async () => {
test('has preload link (enabled in config)', async () => {
const { body } = await get('/')
expect(body).toContain('<link data-n-head="ssr" data-hid="gf-preload" rel="preload" as="style" href="https://fonts.googleapis.com/css2?family=Roboto&amp;family=Lato">')
})
Expand Down

0 comments on commit fa4d4e0

Please sign in to comment.