Exemplo n.º 1
0
        private static void BuildSpeedy(SpeedyLayoutModel model)
        {
            var speedyLinks = GenerateDeferedLinks(new ThemesProvider());

            model.AssetLinks       = speedyLinks;
            model.VanillaJavasript = GetVanillaJavascript();

            model.SpeedyJsEnabled  = SpeedyGenerationSettings.IsCriticalJavascriptEnabledAndPossible(Sitecore.Context.Item);
            model.SpeedyCssEnabled = SpeedyGenerationSettings.IsCriticalStylesEnabled(Sitecore.Context.Item);

            LoadCssIntoModel(model, speedyLinks);
        }
Exemplo n.º 2
0
        public static SpeedyLayoutModel GetSpeedyLayoutModel()
        {
            string            text        = GetPageKey(HttpContext.Current.Request.Url.AbsolutePath) + "speedysettings";
            SpeedyLayoutModel speedyModel = HttpContext.Current.Cache[text] as SpeedyLayoutModel;

            if (speedyModel != null)
            {
                return(speedyModel);
            }

            SpeedyLayoutModel model = new SpeedyLayoutModel();

            model.CacheKey         = text;
            model.SpeedyEnabled    = SpeedyGenerationSettings.IsSpeedyEnabledForPage(Sitecore.Context.Item);
            model.SpeedyJsEnabled  = false;
            model.SpeedyCssEnabled = false;
            bool isOnePassCookieEnabledAndPresent = SpeedyGenerationSettings.IsOnePassCookieEnabled(Sitecore.Context.Item) && !string.IsNullOrWhiteSpace(HttpContext.Current.Request[SpeedyConstants.CookieNames.OnePassCookieName]);

            model.ByPassNotDetected = string.IsNullOrWhiteSpace(HttpContext.Current.Request[SpeedyConstants.ByPass.ByPassParameter]) && !isOnePassCookieEnabledAndPresent;

            if (!model.ByPassNotDetected)
            {
                model.SpeedyEnabled = false;
            }

            if (model.SpeedyEnabled && model.ByPassNotDetected)
            {
                model.AssetLinks       = GenerateDeferedLinks(new ThemesProvider());
                model.SpeedyJsEnabled  = SpeedyGenerationSettings.IsCriticalJavascriptEnabledAndPossible(Sitecore.Context.Item);
                model.SpeedyCssEnabled = SpeedyGenerationSettings.IsCriticalStylesEnabledAndPossible(Sitecore.Context.Item);

                if (model.SpeedyCssEnabled)
                {
                    model.CriticalHtml           = Sitecore.Context.Item.Fields[SpeedyConstants.Fields.CriticalCss].Value;
                    model.SpecialCaseCriticalCss = Sitecore.Context.Item.Fields[SpeedyConstants.Fields.SpecialCaseCriticalCss].Value;
                }
            }
            else
            {
                model.AssetLinks = AssetLinksGenerator.GenerateLinks(new ThemesProvider());
            }

            return(model);
        }
Exemplo n.º 3
0
        public static SpeedyAssetLinks GenerateDeferedLinks(IThemesProvider themesProvider)
        {
            if (AssetContentRefresher.IsPublishing() || IsAddingRendering())
            {
                return(new SpeedyAssetLinks());
            }
            var assetsGenerator = new SpeedyAssetLinksGenerator();
            var links           = assetsGenerator.GenerateSpeedyAssetLinks(themesProvider);
            var linkSpeedy      = new SpeedyAssetLinks(links);

            var AreScriptsDeferred = SpeedyGenerationSettings.IsCriticalJavascriptEnabledAndPossible(Sitecore.Context.Item);

            if (AreScriptsDeferred)
            {
                string deferredSriptsCacheKey = $"speedy-deferred-page-scripts-{Sitecore.Context.Item.ID}";
                string preloadSriptsCacheKey  = $"speedy-preload-page-scripts-{Sitecore.Context.Item.ID}";
                string deferredSriptsCache    = HttpContext.Current.Cache[deferredSriptsCacheKey] as string;
                string preloadSriptsCache     = HttpContext.Current.Cache[preloadSriptsCacheKey] as string;

                if (SpeedyGenerationSettings.IsDebugModeEnabled())
                {
                    deferredSriptsCache = null;
                    preloadSriptsCache  = null;
                }

                if (!string.IsNullOrWhiteSpace(deferredSriptsCache) && !string.IsNullOrWhiteSpace(preloadSriptsCache))
                {
                    linkSpeedy.ClientScriptsRendered = deferredSriptsCache;
                    linkSpeedy.ClientScriptsPreload  = preloadSriptsCache;
                }
                else
                {
                    assetsGenerator.GenerateSpeedyScripts(linkSpeedy);
                    CacheObject(deferredSriptsCacheKey, linkSpeedy.ClientScriptsRendered, GetDependencies(null));
                    CacheObject(preloadSriptsCacheKey, linkSpeedy.ClientScriptsPreload, GetDependencies(null));
                }
            }
            else
            {
                var linksa = AssetLinksGenerator.GenerateLinks(new ThemesProvider());
                linkSpeedy.Scripts = linksa.Scripts;
            }
            return(linkSpeedy);
        }
Exemplo n.º 4
0
        public static SpeedyAssetLinks GenerateDeferedLinks(IThemesProvider themesProvider)
        {
            if (AssetContentRefresher.IsPublishing() || IsAddingRendering())
            {
                return(new SpeedyAssetLinks());
            }
            var assetsGenerator = new SpeedyAssetLinksGenerator();
            var links           = assetsGenerator.GenerateSpeedyAssetLinks(themesProvider);
            var linkSpeedy      = new SpeedyAssetLinks(links);

            var AreScriptsDeferred = SpeedyGenerationSettings.IsCriticalJavascriptEnabledAndPossible(Sitecore.Context.Item);

            if (AreScriptsDeferred)
            {
                assetsGenerator.GenerateSpeedyScripts(linkSpeedy);
            }
            else
            {
                var linksa = AssetLinksGenerator.GenerateLinks(new ThemesProvider());
                linkSpeedy.Scripts = linksa.Scripts;
            }
            return(linkSpeedy);
        }