I need to include some JavaScript in jsp pages:
<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.
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. But I can't do it with 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.
Liferay is using com.liferay.portal.model.Portlet.getTimestamp() to generate the number after t=. You can get the (Liferay) portlet from the PortletContext:
<%
LiferayPortletContext context = (LiferayPortletContext) portletConfig.getPortletContext();
long timestamp = context.getPortlet().getTimestamp();
%>
<script type="text/javascript"
src="<%=request.getContextPath()%>/newsletter/js/newsletter.js?t=<%=timestamp%>">
</script>
Related
I want other web sites to link to js file from my domain, like this:
<script language="javascript" src="http://mySite/jsfile.js"></script>
To avoid the cache problem then I need to add a version parameter to the JS file.
But if the version parameter is static then they have to keep updating the link with every new version, so I need a "CHANGEABLE" parameter like this:
<script language="javascript" src="http://mySite/jsfile.js?new Date().getTime()"></script>
How to do that?
in other way: HOW TO MAKE THEM ALWAYS GET THE LATEST VERSION OF MY JS FILE WITHOUT THE NEED TO RE-UPDATE THE JS URL IN THEIR PAGES.
Thanks in advance for your help :)
You can write your <script> tag with js:
<script language="javascript" src="http://mySite/jsfile.js?new Date().getTime()"></script>
with:
<script>
document.write("<script language="javascript" src="http://mySite/jsfile.js?k=" + Date.now() + "'><\/script>");
</script>
this way its posible to add some number or timesamp after your jsfile.
I would make a script, which call my api. Get the lastest js script code, And include it on site,
this way, it's doesn't matter if it's cached the url for the script.
First, Make a .js file, which use Jquery getScript to get and execute. the script you won't have cached .
get the people to use this. then whenever the site is loaded, it get's a new version of the script from your server.
Jobs done.
Im not providing anycode, since, it's more or less using the Jquery getscript. and the docs for that, is better then any sample i could make.
A client of ours has a Silverstripe website that they're hosting with a company that applies the Cloudflare CDN to their hosting plan.
We can't access the Cloudflare settings but want to alter one of the settings "Rocket Launcher" so it doesn't touch the Silverstripe CMS Javascript files (lib.js, leftandmain.js).
It is possible to make Rocket Launcher ignore a script:
<script data-cfasync="false" src="/javascript.js"></script>
However the CMS javascript is dynamically loaded by core Silverstripe code:
Requirements::combine_files('leftandmain.js', $leftAndMainIncludes);
Is it possible to add the data-cfasync="false" variable to the script tag by extending the core code?
I want the output to read:
<script type="text/javascript" data-cfasync="false" src="/assets/_combinedfiles/leftandmain.js?m=1486678668"></script>
Any help is appreciated.
Doesn't look to be an easy place in Requirements_Backend. Could do it using a RequestFilter. Use a regex or simple replace to modify the response body.
I am getting problem in referencing Javascript file.
My all js files reside in my js folder:MyProject/Js/*.js
Now on my master page i am refering my file like this:
<script src="js/jquery-1.9.1.js"></script>
<script src="js/jquery-1.9.0.min.js" type="text/javascript"></script>
Error showing in console:
SyntaxError: expected expression, got '<'.
On searching i have found that this issue comes due to inappropriate referencing of js files so i have resolve this error by doing this:
<script src="../js/jquery-1.9.1.js"></script>
<script src="../js/jquery-1.9.0.min.js" type="text/javascript"></script>
This above solution works when my .aspx page would be like this:
MyProject/Admin/Abc.aspx //This will work
But problem will occur when any of my .aspx page would be like such:
MyProject/Admin/Subfolder/Abc.aspx // This will not work
My Abc.aspx page contains master page but now in this case this will not load my js files due to ../
So can anybody tell me whats the correct way to reference js files which will work in both the cases??
Note:I am referencing all js files in to my master page and my master page is in:
MyProject/MasterPage.Master
I think you can give a try:
1) Use Bundling to reduce the loading time (Your script will be shorter as well)
2) Use ~/ instead of ../ to make your script/code work even if you relocate the pages.
You can easily find the scripts and codes of jquery bundle if you create a new ASP.NET application in Visual Studio.
I would like to refactor a single page web application project to use Browserify as its JavaScript loading schema. I've researched Browserify but there are still things that I don't know how to solve. Allow me to describe the JavaScript loading schema that is used in the project that I want to refactor.
The first script element is inline to the generated HTML. We need that in order to pass Backend configuration to the JavaScript engine. For example:
<script type="text/javascript">
var OUR_COMPANY = {
settings: {
user: '${user}'
}
};
</script>
Then we begin to load JavaScript files from a CDN and local project in an intermixable manner (notice that we use a Backend variables once again to distinguish where the JavaScript file is located):
<!-- resURL means CDN -->
<script type="text/javascript" src="${properties.resURL}/js/jquery/jquery-2.0.3.min.js"></script>
...
<!-- managerURL means local project -->
<script type="text/javascript" src="${properties.managerURL}/js/the_project/grids/InlineEdits.js"></script>
...
<script type="text/javascript" src="${properties.resURL}/js/jquery/plugin/jqgrid/v4.6.0/js/jquery.jqGrid.m1.min.js"></script>
Can somebody please give me an idea on how to convert this project's JavaScript loading schema so as to replace it with Browserify?
I am new to Jquery and AJAX. I am trying to upload the file using AJAX call. When I set the script reference as from website, its working fine, but when I download it and set reference as local folder, its not working. What is wrong with my code?
When I use :
<script src="http://malsup.github.com/jquery.form.js"></script>
its working fine,
but when I use
<script type="text/javascript" src="http://localhost:8080/Upload/js/jquery.js"></script>
or
<script type="text/javascript" src="js/jquery.js">
its not working......
Add jquery.form.js library in your website folder under js folder, and
Change
<script type="text/javascript" src="js/jquery.js">
To
<script type="text/javascript" src="js/jquery.form.js">
This version points to a file on that web site:
<script src="http://malsup.github.com/jquery.form.js"></script>
This version points to a file on your LOCAL server (machine) via port 8080 (usually NOT a great idea)
<script type="text/javascript" src="http://localhost:8080/Upload/js/jquery.js"></script>
This verison points to a js folder relative to the page it is linked on
<script type="text/javascript" src="js/jquery.js">
In order to use a file locally (like the last two), you will need to download that file, and save it to your web server (or local server) in a folder. In the second example, this would mean saving it to the Upload\js folder at the root of your local servers site (that machine).
In the third example, you would need to find the page it is linked in, create (if not present) a js folder under that folder and save the js file at that location.
Note that it is always a good idea to use the original name form or something similar rather than jQuery.js - as that is often confused with the jQuery library itself.
An examples might be save it as:
jquery.form.js
malsup.jquery.form.js
malsup.version1.jquery.form.js
or some such named instance.
NOTE One way of making this as generic as might be would be to use
<script type="text/javascript" src="/Upload/js/jquery.js"></script>
This points to a folder called Upload with a sub folder js (Upload\js)which is based at the root of your web site. For instance if your site is based at your windows e: drive in a wwwroot folder it might be:
E:\wwwroot\Upload\js\malsup.jquery.form.js