【问题标题】:Liferay: How to minify CSS and JS file included in jspLiferay:如何缩小jsp中包含的CSS和JS文件
【发布时间】:2016-05-20 10:21:21
【问题描述】:

我在我的一个 Liferay portlet 中使用了多个 css 和 js 文件。 liferay-portlet.xml 文件中包含的 CSS 和 JS 文件会自动包含在页面中。

除了 XML 文件中提到的文件外,我使用外部 CSS 和 JS 文件使用链接和脚本标签。

如何缩小这些文件?

<portlet>
    <portlet-name>demo-page</portlet-name>
    <icon>/icon.png</icon>
    <header-portlet-css>/css/main.css</header-portlet-css>
    <header-portlet-css>/css/style.css</header-portlet-css>
    <footer-portlet-javascript>/js/main.js</footer-portlet-javascript>
</portlet>

我想在 page1.jsp 中使用 main.css,但不在 page2.jsp 中。 我可以为 liferay-portlet.xml 中包含的文件定义页面范围吗?

【问题讨论】:

    标签: javascript css liferay liferay-6.2


    【解决方案1】:

    您只需将您的文件用于 css:&lt; link rel="stylesheet" href="&lt;%=request.getContextPath()%&gt;/my_sources/css/style.css"/&gt;,liferay 会负责缩小(除非您在 portal-ext.properties 中禁用它)。

    【讨论】:

    • 即使 theme.css.fast.load 值为 true 也无法正常工作
    • 这很奇怪...您是否尝试在您的 URL 中添加 cc_fast_load=1 作为请求参数?
    • 只是在 HTML 中引用一些随机的 css 不会使 Liferay 处理该文件。我建议将 CSS 添加到主题中 - 它会略微增加主题的 CSS(这将被缩小)并且你已经设置好了。
    【解决方案2】:

    在您的门户扩展中:

    # Set this property to true to load the theme's merged CSS files for faster
    # loading for production.
    #
    # Set this property to false for easier debugging for development. You can
    # also disable fast loading by setting the URL parameter "css_fast_load" to
    # "0".
    #
    theme.css.fast.load=true
    
    
    # Set this property to true to load the packed version of files listed in
    # the properties "javascript.barebone.files" or
    # "javascript.everything.files".
    #
    # Set this property to false for easier debugging for development. You can
    # also disable fast loading by setting the URL parameter "js_fast_load" to
    # "0".
    #
    javascript.fast.load=true
    

    【讨论】:

      【解决方案3】:

      Liferay 仅缩小主题中包含的资源,并将其添加到 liferay-portlet.xml 中的 portlet。如果您想对所有 css 和 js 文件执行此操作,您应该为 Liferay Servlet 过滤器实现一个挂钩,并且在过滤器内您可以根据需要处理任何资源。过滤器在对外部资源的所有请求中执行。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-01-14
        • 1970-01-01
        • 2013-11-30
        • 2015-01-18
        • 2013-06-28
        • 1970-01-01
        • 2018-04-21
        相关资源
        最近更新 更多