简体   繁体   English

Liferay Portlet部署时间戳

[英]Liferay portlet deploy timestamp

I need to include some JavaScript in jsp pages: 我需要在jsp页面中包含一些JavaScript:

<script type="text/javascript" src="<%=request.getContextPath()%>/newsletter/js/newsletter.js"></script>

When I deploy a new portlet version and I change this JavaScript file, some users see the old version of this file. 当我部署新的Portlet版本并更改此JavaScript文件时,某些用户会看到此文件的旧版本。

I saw that Liferay adds last deploy timestamp to javascripts ( ...js?t=14573725543 ), and I can do it if I add this file to liferay-portlet.xml . 我看到Liferay将上次部署时间戳记添加到了javascripts( ...js?t=14573725543 )中,如果将此文件添加到liferay-portlet.xml ,则可以这样做。 But I can't do it with newsletter.js . 但是我不能用newsletter.js做到。 Sometimes I need no load this file. 有时我不需要加载该文件。

Is it possible to add manually this automatic timestamp? 是否可以手动添加此自动时间戳? I do something similar in a theme with $theme_timestamp . 我在$theme_timestamp主题中做了类似的$theme_timestamp

Liferay is using com.liferay.portal.model.Portlet.getTimestamp() to generate the number after t= . Liferay使用com.liferay.portal.model.Portlet.getTimestamp()生成t=之后的数字。 You can get the (Liferay) portlet from the PortletContext: 您可以从PortletContext获得(Liferay)Portlet:

<%
LiferayPortletContext context = (LiferayPortletContext) portletConfig.getPortletContext();
long timestamp = context.getPortlet().getTimestamp();
%>
<script type="text/javascript" 
        src="<%=request.getContextPath()%>/newsletter/js/newsletter.js?t=<%=timestamp%>">
</script>

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

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