Skip to content

Commit e82eef9

Browse files
alan-agius4filipesilva
authored andcommitted
refactor(@angular-devkit/build-angular): remove WOFF handling from inline-fonts processor
BREAKING CHANGE: We remove inlining of Google fonts in WOFF format since IE 11 is no longer supported. Other supported browsers use WOFF2.
1 parent 32101e4 commit e82eef9

File tree

6 files changed

+6
-66
lines changed

6 files changed

+6
-66
lines changed

packages/angular_devkit/build_angular/src/browser/index.ts

-2
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,6 @@ export function buildWebpackBrowser(
631631
if (options.index) {
632632
spinner.start('Generating index html...');
633633

634-
const WOFFSupportNeeded = !buildBrowserFeatures.isFeatureSupported('woff2');
635634
const entrypoints = generateEntryPoints({
636635
scripts: options.scripts ?? [],
637636
styles: options.styles ?? [],
@@ -642,7 +641,6 @@ export function buildWebpackBrowser(
642641
entrypoints,
643642
deployUrl: options.deployUrl,
644643
sri: options.subresourceIntegrity,
645-
WOFFSupportNeeded,
646644
optimization: normalizedOptimization,
647645
crossOrigin: options.crossOrigin,
648646
postTransform: transforms.indexHtml,

packages/angular_devkit/build_angular/src/browser/specs/font-optimization_spec.ts

+1-12
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,13 @@ describe('Browser Builder font optimization', () => {
4040
expect(html).toContain(`font-family: 'Roboto'`);
4141
});
4242

43-
it('should not add woff when IE support is not needed', async () => {
43+
it('should not add woff', async () => {
4444
const { files } = await browserBuild(architect, host, target, overrides);
4545
const html = await files['index.html'];
4646
expect(html).toContain(`format('woff2');`);
4747
expect(html).not.toContain(`format('woff');`);
4848
});
4949

50-
it('should add woff when IE support is needed', async () => {
51-
host.writeMultipleFiles({
52-
'.browserslistrc': 'IE 11',
53-
});
54-
55-
const { files } = await browserBuild(architect, host, target, overrides);
56-
const html = await files['index.html'];
57-
expect(html).toContain(`format('woff2');`);
58-
expect(html).toContain(`format('woff');`);
59-
});
60-
6150
it('should remove comments and line breaks when styles optimization is true', async () => {
6251
const { files } = await browserBuild(architect, host, target, {
6352
optimization: {

packages/angular_devkit/build_angular/src/dev-server/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,6 @@ export function serveWebpackBrowser(
328328
sri: browserOptions.subresourceIntegrity,
329329
postTransform: transforms.indexHtml,
330330
optimization: normalizeOptimization(browserOptions.optimization),
331-
WOFFSupportNeeded: !buildBrowserFeatures.isFeatureSupported('woff2'),
332331
crossOrigin: browserOptions.crossOrigin,
333332
lang: locale,
334333
}),

packages/angular_devkit/build_angular/src/utils/index-file/index-html-generator.ts

-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export interface IndexHtmlGeneratorOptions {
3636
postTransform?: IndexHtmlTransform;
3737
crossOrigin?: CrossOriginValue;
3838
optimization?: NormalizedOptimizationOptions;
39-
WOFFSupportNeeded: boolean;
4039
}
4140

4241
export type IndexHtmlTransform = (content: string) => Promise<string>;
@@ -126,7 +125,6 @@ function augmentIndexHtmlPlugin(generator: IndexHtmlGenerator): IndexHtmlGenerat
126125
function inlineFontsPlugin({ options }: IndexHtmlGenerator): IndexHtmlGeneratorPlugin {
127126
const inlineFontsProcessor = new InlineFontsProcessor({
128127
minify: options.optimization?.styles.minify,
129-
WOFFSupportNeeded: options.WOFFSupportNeeded,
130128
});
131129

132130
return async (html) => inlineFontsProcessor.process(html);

packages/angular_devkit/build_angular/src/utils/index-file/inline-fonts.ts

+5-19
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,19 @@ const cacheFontsPath: string | undefined = cachingDisabled
2020
: findCachePath('angular-build-fonts');
2121
const packageVersion = require('../../../package.json').version;
2222

23-
const enum UserAgent {
24-
Chrome = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36',
25-
IE = 'Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11. 0) like Gecko',
26-
}
27-
2823
interface FontProviderDetails {
2924
preconnectUrl: string;
30-
seperateRequestForWOFF: boolean;
3125
}
3226

3327
export interface InlineFontsOptions {
3428
minify?: boolean;
35-
WOFFSupportNeeded: boolean;
3629
}
3730

3831
const SUPPORTED_PROVIDERS: Record<string, FontProviderDetails> = {
3932
'fonts.googleapis.com': {
40-
seperateRequestForWOFF: true,
4133
preconnectUrl: 'https://fonts.gstatic.com',
4234
},
4335
'use.typekit.net': {
44-
seperateRequestForWOFF: false,
4536
preconnectUrl: 'https://use.typekit.net',
4637
},
4738
};
@@ -160,8 +151,8 @@ export class InlineFontsProcessor {
160151
return transformedContent;
161152
}
162153

163-
private async getResponse(url: URL, userAgent: UserAgent): Promise<string> {
164-
const key = `${packageVersion}|${url}|${userAgent}`;
154+
private async getResponse(url: URL): Promise<string> {
155+
const key = `${packageVersion}|${url}`;
165156

166157
if (cacheFontsPath) {
167158
const entry = await cacache.get.info(cacheFontsPath, key);
@@ -186,7 +177,8 @@ export class InlineFontsProcessor {
186177
agent,
187178
rejectUnauthorized: false,
188179
headers: {
189-
'user-agent': userAgent,
180+
'user-agent':
181+
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36',
190182
},
191183
},
192184
(res) => {
@@ -226,13 +218,7 @@ export class InlineFontsProcessor {
226218
return undefined;
227219
}
228220

229-
// The order IE -> Chrome is important as otherwise Chrome will load woff1.
230-
let cssContent = '';
231-
if (this.options.WOFFSupportNeeded && provider.seperateRequestForWOFF) {
232-
cssContent += await this.getResponse(url, UserAgent.IE);
233-
}
234-
235-
cssContent += await this.getResponse(url, UserAgent.Chrome);
221+
let cssContent = await this.getResponse(url);
236222

237223
if (this.options.minify) {
238224
cssContent = cssContent

packages/angular_devkit/build_angular/src/utils/index-file/inline-fonts_spec.ts

-30
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ describe('InlineFontsProcessor', () => {
2020

2121
it('works with // protocol', async () => {
2222
const inlineFontsProcessor = new InlineFontsProcessor({
23-
WOFFSupportNeeded: false,
2423
minify: false,
2524
});
2625

@@ -31,7 +30,6 @@ describe('InlineFontsProcessor', () => {
3130
it('should inline supported fonts and icons in HTML', async () => {
3231
const inlineFontsProcessor = new InlineFontsProcessor({
3332
minify: false,
34-
WOFFSupportNeeded: false,
3533
});
3634

3735
const html = await inlineFontsProcessor.process(`
@@ -56,7 +54,6 @@ describe('InlineFontsProcessor', () => {
5654
it('should inline multiple fonts from a single request with minification enabled', async () => {
5755
const inlineFontsProcessor = new InlineFontsProcessor({
5856
minify: true,
59-
WOFFSupportNeeded: false,
6057
});
6158

6259
const html = await inlineFontsProcessor.process(`
@@ -76,28 +73,15 @@ describe('InlineFontsProcessor', () => {
7673

7774
it('works with http protocol', async () => {
7875
const inlineFontsProcessor = new InlineFontsProcessor({
79-
WOFFSupportNeeded: false,
8076
minify: false,
8177
});
8278

8379
const html = await inlineFontsProcessor.process(content.replace('https://', 'http://'));
8480
expect(html).toContain(`format('woff2');`);
8581
});
8682

87-
it('should include WOFF1 definitions when `WOFF1SupportNeeded` is true', async () => {
88-
const inlineFontsProcessor = new InlineFontsProcessor({
89-
WOFFSupportNeeded: true,
90-
minify: false,
91-
});
92-
93-
const html = await inlineFontsProcessor.process(content);
94-
expect(html).toContain(`format('woff2');`);
95-
expect(html).toContain(`format('woff');`);
96-
});
97-
9883
it('should remove comments and line breaks when `minifyInlinedCSS` is true', async () => {
9984
const inlineFontsProcessor = new InlineFontsProcessor({
100-
WOFFSupportNeeded: false,
10185
minify: true,
10286
});
10387

@@ -108,7 +92,6 @@ describe('InlineFontsProcessor', () => {
10892

10993
it('should add preconnect hint', async () => {
11094
const inlineFontsProcessor = new InlineFontsProcessor({
111-
WOFFSupportNeeded: true,
11295
minify: false,
11396
});
11497

@@ -128,21 +111,8 @@ describe('InlineFontsProcessor', () => {
128111
<body></body>
129112
</html>`;
130113

131-
it('should include WOFF1 definitions when `WOFF1SupportNeeded` is true', async () => {
132-
const inlineFontsProcessor = new InlineFontsProcessor({
133-
WOFFSupportNeeded: true,
134-
minify: false,
135-
});
136-
137-
const html = await inlineFontsProcessor.process(content);
138-
expect(html).not.toContain('href="https://use.typekit.net/plm1izr.css"');
139-
expect(html).toContain(`format("woff2")`);
140-
expect(html).toContain(`format("woff")`);
141-
});
142-
143114
it('should add preconnect hint', async () => {
144115
const inlineFontsProcessor = new InlineFontsProcessor({
145-
WOFFSupportNeeded: true,
146116
minify: false,
147117
});
148118

0 commit comments

Comments
 (0)