Пример #1
0
        /// <summary>
        /// Throwing the entire CSS block inside the Critical head block is not the most streamlined method. Ideally the web team would use the NPM Critical
        /// package. However This is fallback for the lazy web team that ultimately just won't do that.
        /// Loop over the CSS assets, download the contents and append to one big Critical block
        /// </summary>
        /// <param name="assetLinks"></param>
        /// <returns></returns>
        private static string BuildEntireCssBlock(SpeedyAssetLinks assetLinks)
        {
            StringBuilder entireCriticalBlock = new StringBuilder();

            // Lookup the filters
            var nameValueListString = SpeedyGenerationSettings.GetGlobalSettingsItemFromContext()[SpeedyConstants.GlobalSettings.Fields.CSSFilter];

            //Converts the string to NameValueCollection
            System.Collections.Specialized.NameValueCollection nameValueList = Sitecore.Web.WebUtil.ParseUrlParameters(nameValueListString);

            foreach (var style in assetLinks.PlainStyles)
            {
                ApplyStyleFile(nameValueList, entireCriticalBlock, style);
            }

            entireCriticalBlock = entireCriticalBlock.Replace("font-family:", "font-display:swap;font-family:");

            return(entireCriticalBlock.ToString());
        }