简体   繁体   English

外部JS未在liferay 7 GA4中加载

[英]External JS not loading in liferay 7 GA4

I have added external JS in theme and portlet but JS not loading first time page loading.我在主题和 portlet 中添加了外部 JS,但 JS 没有加载第一次页面加载。

I am using below code :我正在使用以下代码:

 <script>
    Liferay.Loader.define._amd = Liferay.Loader.define.amd;
    Liferay.Loader.define.amd = false;
</script>
    <script src="${javascript_folder}/jquery.jscrollpane.min.js" />  
    <script src="${javascript_folder}/jquery.mousewheel.js" />  
    <script src="${javascript_folder}/common.js" /> 

<script>
    Liferay.Loader.define.amd = Liferay.Loader.define._amd;
</script>

Please help me.请帮我。

As per given Liferay version L7 GA4,根据给定的 Liferay 版本 L7 GA4,

Follow these steps:请按照以下步骤操作:

Open the Control Panel, navigate to Configuration → System Settings.打开控制面板,导航至配置 → 系统设置。

Click JavaScript Loader under the Foundation tab.单击 Foundation 选项卡下的 JavaScript Loader。

Uncheck the expose global option.取消选中公开全局选项。

Reference Link - https://help.liferay.com/hc/en-us/articles/360018161931-Using-External-Libraries-#using-libraries-that-you-host参考链接- https://help.liferay.com/hc/en-us/articles/360018161931-Using-External-Libraries-#using-libraries-that-you-host

Also, there is some alternative second solution of Liferay Version which I used L7.1 and L7.2此外,我使用 L7.1 和 L7.2 的 Liferay 版本还有一些替代的第二个解决方案

Below code, I am adding in my module project下面的代码,我在我的模块项目中添加

@Component(immediate = true, service = DynamicInclude.class)
public class JSTopHeadDynamicInclude extends BaseDynamicInclude {

  @Override
    public void include(
            HttpServletRequest request, HttpServletResponse response,
            String key)
        throws IOException {

    PrintWriter printWriter = response.getWriter();

    String content = "<script src=\"/o/my-custom-dynamic-include/jquery.jscrollpane.min.js\" />";
    content += "<script src=\"/o/my-custom-dynamic-include/jquery.mousewheel.js\" />";
    content += "<script src=\"/o/my-custom-dynamic-include/common.js\" />";
    printWriter.println(content);
    }

    @Override
    public void register(
        DynamicInclude.DynamicIncludeRegistry dynamicIncludeRegistry) {

        dynamicIncludeRegistry.register(
      "/html/common/themes/top_js.jspf#resources"
    );
    }
}

You can add these js files in your OSGI module location if "js" folder did not exist then you can create and add your js files.如果“js”文件夹不存在,您可以将这些 js 文件添加到您的 OSGI 模块位置,然后您可以创建和添加您的 js 文件。

**src/main/resource/META-INF/resources/js/**

Also, You should register Web-ContextPath in BND.BND file for module此外,您应该在 BND.BND 文件中为模块注册 Web-ContextPath

**Web-ContextPath: /my-custom-dynamic-include**

Reference Link - https://help.liferay.com/hc/en-us/articles/360018165751-Top-JS-Dynamic-Include参考链接- https://help.liferay.com/hc/en-us/articles/360018165751-Top-JS-Dynamic-Include

I am using the second solution.我正在使用第二种解决方案。 - Which is working fine. - 工作正常。

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

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