Reputation: 8855
I have an issue with Javascript reloading due to Tiles.
Tiles-definition.xml
<tiles-definitions>
<definition name="template-main" template="/WEB-INF/jsp/home.jsp">
<put-attribute name="header-main-content" value="/WEB-INF/jsp/header_main.jsp"/>
<put-attribute name="header-quote-content" value="/WEB-INF/jsp/header_quote.jsp" />
<put-attribute name="menu-content" value="/WEB-INF/jsp/menu.jsp" />
<put-attribute name="body-content" value="/WEB-INF/jsp/slides.jsp" />
<put-attribute name="footer-content" value="/WEB-INF/jsp/footer.jsp" />
</definition>
<definition name="template-main-login" extends="template-main">
<put-attribute name="header-main-content" value="/WEB-INF/jsp/header_main.jsp" />
</definition>
</tiles-definitions>
home.jsp
<body style="background-color: #5F9EA0">
<head>
<script src="<c:url value="/resources/js/jquery-1.11.1.js" />"></script>
<script src="<c:url value="/resources/js/example.js" />"></script>
bla bla ..
example.js
$(document).ready(function() {
setTimeout(function () {
popUp('show');
}, 1000);
});
I am using Spring-MVC:
When the application is loaded I am returning the view as template-main. So the first template definition is called and the application is opened with a login popup as I am calling the popup on document load.
Problem:
Now when I give the login credentials and submit I am calling template-main-login which in turn is extending the template-main. Now the problem is, the Javascript which I have included in the home.jsp is loading again (may be since I am extending the template-main layout) such that I am getting the popup opened for the second time which I want to stop.
So please let me know how to stop the popup opening again.
Upvotes: 0
Views: 272
Reputation: 20182
You need to ensure that your JS files have the proper cache control/expires headers (either set a long date or use ETags). If you use ETags, the static files will still query the server implementation to check if the file hash has changed or not. You can avoid that by using expires headers on all your static files so that the browser can cache them and load them from the local computing device as opposed to sending in a HTTP request to your server.
Upvotes: 0
Reputation: 36
i would suggest rather than making home.jsp as your template make a separate jsp only for your template and basetemplate will have generic things like loading external js and css files and keep specific js code in specific jsp
Upvotes: 1