diff --git a/lib/module.js b/lib/module.js index 7588360..0fc81f3 100644 --- a/lib/module.js +++ b/lib/module.js @@ -107,17 +107,24 @@ module.exports = function (moduleOptions) { }) } - // import CSS - this.options.head.style = this.options.head.style || [] - this.options.head.style.push({ - hid: 'gf-style', - pbody: true, - innerHTML: `@import "${url}"` + // append CSS + this.options.head.script = this.options.head.script || [] + this.options.head.script.push({ + hid: 'gf-script', + innerHTML: `(function(){var l=document.createElement('link');l.rel="stylesheet";l.href="${url}";document.querySelector("head").appendChild(l);})();` + }) + + // no-JS fallback + this.options.head.noscript = this.options.head.noscript || [] + this.options.head.noscript.push({ + hid: 'gf-noscript', + innerHTML: `` }) // Disable sanitazions this.options.head.__dangerouslyDisableSanitizersByTagID = this.options.head.__dangerouslyDisableSanitizersByTagID || {} - this.options.head.__dangerouslyDisableSanitizersByTagID['gf-style'] = ['innerHTML'] + this.options.head.__dangerouslyDisableSanitizersByTagID['gf-script'] = ['innerHTML'] + this.options.head.__dangerouslyDisableSanitizersByTagID['gf-noscript'] = ['innerHTML'] }) } diff --git a/test/basic.test.js b/test/basic.test.js index 596c8d2..7e8c15f 100644 --- a/test/basic.test.js +++ b/test/basic.test.js @@ -11,11 +11,28 @@ describe('basic', () => { await nuxt.close() }) - test('render', async () => { + test('has prefetch link', async () => { const html = await get('/') expect(html).toContain('') + }) + + test('has preconnect link', async () => { + const html = await get('/') expect(html).toContain('') + }) + + test('has preload link', async () => { + const html = await get('/') expect(html).toContain('') - expect(html).toContain('') + }) + + test('has script to import font css', async () => { + const html = await get('/') + expect(html).toContain('data-hid="gf-script"') + }) + + test('has noscript fallback', async () => { + const html = await get('/') + expect(html).toContain('data-hid="gf-noscript"') }) })