@@ -42,7 +42,6 @@ import { getConfiguration } from './config';
4242import { getAnalyticsInitCode } from './util/analyticsUtils' ;
4343
4444import { historyMiddlewares , render } from './routes' ;
45- import { LOCAL_STORAGE_EMITTER_PATH } from './util/path' ;
4645import ErrorHandlerSSR from './component/ErrorHandlerSSR' ;
4746
4847// Look up paths for various asset files
@@ -327,94 +326,85 @@ export default async function serve(req, res, next) {
327326 res . write ( `<html lang="${ locale } ">\n` ) ;
328327 res . write ( '<head>\n' ) ;
329328
330- // local storage emitter is used from a hidden iframe and these are not necessary for it
331- if ( req . url !== LOCAL_STORAGE_EMITTER_PATH ) {
332- // Write preload hints before doing anything else
333- if ( process . env . NODE_ENV !== 'development' ) {
334- res . write ( getAnalyticsInitCode ( config , req . hostname ) ) ;
335-
336- const preloads = [
337- { as : 'style' , href : config . URL . FONT } ,
338- {
339- as : 'style' ,
340- href : `${ ASSET_URL } /${ assets [ `${ config . CONFIG } _theme.css` ] } ` ,
341- crossorigin : true ,
342- } ,
343- ...mainAssets . map ( asset => ( {
344- as : asset . endsWith ( '.css' ) ? 'style' : 'script' ,
345- href : `${ ASSET_URL } /${ asset } ` ,
346- crossorigin : true ,
347- } ) ) ,
348- ] ;
349-
350- preloads . forEach ( ( { as, href, crossorigin } ) =>
351- res . write (
352- `<link rel="preload" as="${ as } " ${
353- crossorigin ? 'crossorigin' : ''
354- } href="${ href } ">\n`,
355- ) ,
356- ) ;
357-
358- const preconnects = [ config . URL . API_URL , config . URL . MAP_URL ] ;
359-
360- if ( config . staticMessagesUrl ) {
361- preconnects . push ( config . staticMessagesUrl ) ;
362- }
329+ // Write preload hints before doing anything else
330+ if ( process . env . NODE_ENV !== 'development' ) {
331+ res . write ( getAnalyticsInitCode ( config , req . hostname ) ) ;
332+
333+ const preloads = [
334+ { as : 'style' , href : config . URL . FONT } ,
335+ {
336+ as : 'style' ,
337+ href : `${ ASSET_URL } /${ assets [ `${ config . CONFIG } _theme.css` ] } ` ,
338+ crossorigin : true ,
339+ } ,
340+ ...mainAssets . map ( asset => ( {
341+ as : asset . endsWith ( '.css' ) ? 'style' : 'script' ,
342+ href : `${ ASSET_URL } /${ asset } ` ,
343+ crossorigin : true ,
344+ } ) ) ,
345+ ] ;
346+
347+ preloads . forEach ( ( { as, href, crossorigin } ) =>
348+ res . write (
349+ `<link rel="preload" as="${ as } " ${
350+ crossorigin ? 'crossorigin' : ''
351+ } href="${ href } ">\n`,
352+ ) ,
353+ ) ;
363354
364- preconnects . forEach ( href =>
365- res . write ( `<link rel="preconnect" crossorigin href="${ href } ">\n` ) ,
366- ) ;
355+ const preconnects = [ config . URL . API_URL , config . URL . MAP_URL ] ;
367356
368- res . write (
369- `<link rel="stylesheet" type="text/css" crossorigin href="${ ASSET_URL } /${
370- assets [ `${ config . CONFIG } _theme.css` ]
371- } "/>\n`,
372- ) ;
373- mainAssets
374- . filter ( asset => asset . endsWith ( '.css' ) )
375- . forEach ( asset =>
376- res . write (
377- `<link rel="stylesheet" type="text/css" crossorigin href="${ ASSET_URL } /${ asset } "/>\n` ,
378- ) ,
379- ) ;
357+ if ( config . staticMessagesUrl ) {
358+ preconnects . push ( config . staticMessagesUrl ) ;
380359 }
381360
361+ preconnects . forEach ( href =>
362+ res . write ( `<link rel="preconnect" crossorigin href="${ href } ">\n` ) ,
363+ ) ;
364+
382365 res . write (
383- `<link rel="stylesheet" type="text/css" href="${ config . URL . FONT } "/>\n` ,
366+ `<link rel="stylesheet" type="text/css" crossorigin href="${ ASSET_URL } /${
367+ assets [ `${ config . CONFIG } _theme.css` ]
368+ } "/>\n`,
384369 ) ;
370+ mainAssets
371+ . filter ( asset => asset . endsWith ( '.css' ) )
372+ . forEach ( asset =>
373+ res . write (
374+ `<link rel="stylesheet" type="text/css" crossorigin href="${ ASSET_URL } /${ asset } "/>\n` ,
375+ ) ,
376+ ) ;
377+ }
378+ res . write (
379+ `<link rel="stylesheet" type="text/css" href="${ config . URL . FONT } "/>\n` ,
380+ ) ;
385381
386- res . write ( `<script>\n${ polyfills } \n</script>\n` ) ;
382+ res . write ( `<script>\n${ polyfills } \n</script>\n` ) ;
387383
388- const head = Helmet . rewind ( ) ;
384+ const head = Helmet . rewind ( ) ;
389385
390- if ( head ) {
391- res . write ( head . title . toString ( ) ) ;
392- res . write ( head . meta . toString ( ) ) ;
393- res . write ( head . link . toString ( ) ) ;
394- }
386+ if ( head ) {
387+ res . write ( head . title . toString ( ) ) ;
388+ res . write ( head . meta . toString ( ) ) ;
389+ res . write ( head . link . toString ( ) ) ;
395390 }
396391
397392 res . write ( '</head>\n' ) ;
398393 res . write ( '<body>\n' ) ;
399394
400- // local storage emitter is used from a hidden iframe and these are not necessary for it
401- if ( req . url !== LOCAL_STORAGE_EMITTER_PATH ) {
402- if ( process . env . NODE_ENV !== 'development' ) {
403- res . write ( '<script>\n' ) ;
404- res . write ( `fetch('${ ASSET_URL } /${ assets [ spriteName ] } ')
395+ if ( process . env . NODE_ENV !== 'development' ) {
396+ res . write ( '<script>\n' ) ;
397+ res . write ( `fetch('${ ASSET_URL } /${ assets [ spriteName ] } ')
405398 .then(function(response) {return response.text();}).then(function(blob) {
406399 var div = document.createElement('div');
407400 div.innerHTML = blob;
408401 document.body.insertBefore(div, document.body.childNodes[0]);
409402 });` ) ;
410- res . write ( '</script>\n' ) ;
411- } else {
412- res . write ( '<div>\n' ) ;
413- res . write (
414- fs . readFileSync ( `${ appRoot } _static/${ spriteName } ` ) . toString ( ) ,
415- ) ;
416- res . write ( '</div>\n' ) ;
417- }
403+ res . write ( '</script>\n' ) ;
404+ } else {
405+ res . write ( '<div>\n' ) ;
406+ res . write ( fs . readFileSync ( `${ appRoot } _static/${ spriteName } ` ) . toString ( ) ) ;
407+ res . write ( '</div>\n' ) ;
418408 }
419409
420410 res . write ( contentWithBreakpoint || '<div id="app" />' ) ;
@@ -425,16 +415,13 @@ export default async function serve(req, res, next) {
425415 ) } ;\n</script>\n`,
426416 ) ;
427417
428- // local storage emitter is used from a hidden iframe and it does not use relay
429- if ( req . url !== LOCAL_STORAGE_EMITTER_PATH ) {
430- res . write ( '<script>\n' ) ;
431- res . write (
432- `window.__RELAY_PAYLOADS__ = ${ serialize ( JSON . stringify ( relayData ) , {
433- isJSON : true ,
434- } ) } `,
435- ) ;
436- res . write ( '\n</script>\n' ) ;
437- }
418+ res . write ( '<script>\n' ) ;
419+ res . write (
420+ `window.__RELAY_PAYLOADS__ = ${ serialize ( JSON . stringify ( relayData ) , {
421+ isJSON : true ,
422+ } ) } `,
423+ ) ;
424+ res . write ( '\n</script>\n' ) ;
438425
439426 if ( process . env . NODE_ENV === 'development' ) {
440427 res . write ( '<script async src="/proxy/js/main.js"></script>\n' ) ;
0 commit comments