简体   繁体   English

仅在页面中包含来自使用过的插件的脚本

[英]Only include scripts from used plugins in page

Is it possible to only include the scripts etc. that are actually used on the site/page in the HTML output shown to the world? 是否可以仅将网站/页面上实际使用的脚本等包含在向全世界显示的HTML输出中?

Loading the JS and CSS files for all installed plugins and the admin interface (like the following), slows down the page a lot: 为所有已安装的插件和管理界面(如下所示)加载JS和CSS文件会大大降低页面速度:

var ip = {"baseUrl":"http:\/\/localhost\/ImpressPages\/","safeMode":false,"languageId":1...

Thanks Morten 谢谢莫滕

Each plugin decides what assets should be included on each page load. 每个插件决定应在每次页面加载中包括哪些资产。 Despite that you can create your own plugin that follows your own logic and removes some assets before page is rendered (I'd use ipBeforeController event for that). 尽管如此,您仍可以创建自己的插件来遵循自己的逻辑,并在呈现页面之前删除一些资产(为此,我将使用ipBeforeController事件)。 _1 means low priority to make sure your script is the last in a row. _1表示优先级低,无法确保脚本是连续的。

class Event
{
    public static function ipBeforeController_1()
    {
        // Get all added JavaScript files
        $allJs = \Ip\ServiceLocator::pageAssets()->getJavascript();

        // ... your logic ...

        // Remove
        \Ip\ServiceLocator::pageAssets()->removeJavascript($fileName);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM