Web page cannot load javascript files from primefaces library - javascript

I use primefaces 6.0 and Spark-layout in my project.
It works on localhost very well.
But when I upload it to the server (jboss or tomcat does not differ), sometimes the page cannot load.
It happens randomly. The page stucks while loading.
When I look the server logs :
It waits too much to log this line:
"GET /XXX/javax.faces.resource/images/preloader.gif.xhtml?ln=spark-layout HTTP/1.1" 200 17824
Also I have seen this in log :
"WARNING [http-nio-80-exec-27] com.sun.faces.application.resource.ResourceHandlerImpl.logMissingResource JSF1064: Unable to find or serve resource, components.js, from library, primefaces."
I have continued to investigate, and seen that, when the problem occurs, the page waits to load .js files from primefaces library.
Page stucks at this line in the head :
script type="text/javascript" src="/XXX/javax.faces.resource/jquery/jquery.js.xhtml?ln=primefaces&v=6.0">
Other .js files cannot be loaded:
script type="text/javascript"
src="/XXX/javax.faces.resource/jquery/jquery-plugins.js.xhtml?ln=primefaces&v=6.0">
script type="text/javascript"
src="/XXX/javax.faces.resource/core.js.xhtml?ln=primefaces&v=6.0">
As a result, what can I do to get rid of this problem :)
Thanks...

Related

Failed to load resource: the server responded with a status of 404 ()

I have written a small code using index.html and three .js files. It was working fine if i run it through my local. As soon as i uploaded it to github and hosted my webpage and opened it the above error is coming. i am attaching the url of my github page : https://sravya160597.github.io/courseracss/mod4_solution/index.html
please help me if anyone has a solution for this.
Taking a look at the page source, and comparing to your github repository, it appears that the problem is case sensitivity in github pages (whereas your localhost must be case-insensitive). Both your SpeakHello.js and SpeakGoodBye.js should start with a lowercase, as follows:
<head>
...
<script src="js/speakHello.js"></script>
<script src="js/speakGoodBye.js"></script>
<script src="js/script.js"></script>
</head>

<script> only loads half the time -- "Loading failed for the <script> with source", and only works when Firefox sends a range in the request

First off, apologies as I'm not experienced with StackOverflow. I also am clueless as to what the problem is.
I'm running a Flask server, and all other scripts have worked fine up to this point. However, when I attempt to load pdf.js in the same way, it only loads some of the time. Other times, it give this error in the Firefox console:
Loading failed for the <script> with source
However, I noticed that when it does work, it always sends a Range in the header.
I've tried loading it from another source, which worked fine. I've tried several different type in the <script> tag, from text/javascript to application/javascript to just blank. I've also tried changing how it's loaded in the JINJA2 template.
<script type="text/javascript" src="/static/pdfjs-dist/build/pdf.js">
</script>
Any ideas on what this is? Thank you!
EDIT:
Working Network Tab
Working Request
Non-Working Request
Non-Working Network Tab

Cache is not updating in browsers

I loaded jquery.min.js in head tag using script tag as below. this version was 1.2.6.
<script type="text/javascript" src="JS/jquery.min.js?v=1.2.6"></script>
<script type="text/javascript" src="JS/jquery-migrate-3.0.0.min.js"></script>
Then I cleared cache and loaded page (that one is ASPX)
So above jquery.min.js?v=1.2.6 is cached in browser now.
Migrate plugin is 3.0.0 which has issue with this version of jQuery.
So I changed content of (I know I can use different path anyway) jquery.min.js from 3.2.1 jQuery file and script tag changed to
<script type="text/javascript" src="JS/jquery.min.js?v=3.2.1"></script>
I reloaded same page at that time also it gives error of migrate plugin. in console also error is in JS/jquery.min.js?v=1.2.6
When I reload it second time (without clearing cache) , then it is not showing error anymore and also if I clear cache at first time then also error is not present.
What's wrong am I doing?
Here it doesn't matter which error it is but only matters is why it is occurring even after querystring is different.

Javascript files intermittently rendering as blank even when loaded from cache

I have a web application that loads a handful of javascript (10-15) files per page. The problem I'm having is some of these files get "loaded" as blank files according to Internet Explorer 10 Developer Tools, but the problem is not consistently reproducible. If you refresh the page a couple times, the .js file does load properly. This issue happens if the file is loaded from cache (response 304) or if it's fresh from the server (response 200). We use CTRL+F5 to force a 200 response. Obviously a "blank" javascript file is throwing all types of errors because the code is simply not there to execute.
Screen shot #1: The javascript file in question is search.js. But as you can see in developer tools under the script tab the file is "blank".
Screen shot #2: If we look under the network tab you can see the file was loaded OK
Now here is where it gets interesting, if you click on "Go to detailed view" button the Response body for this file is the correct Javascript code. The Request and Response headers look correct as well.
Has anyone ever seen this before? We can't seem to reproduce this problem in Chrome or Firefox but that doesn't mean it's not happening there.
<script type='text/javascript' src='wherever.js'></script> could be what you need. Most of those are showing up as application/javascript.

Why does Cordova 2.7.0 JS seemingly no longer work on remote pages?

Background
I'm attempting to upgrade an iOS app built on Cordova 2.0 to version 2.7.
It's basically a welcome screen that points to a remote search engine (please withhold comments about app validity and likely approval, as we're past that), and we were using the ChildBrowser plugin to enable opening links in a sub browser so as not to trap the user in the Cordova webview.
Cordova 2.7 has a feature called InAppBrowser I am hoping to use instead of ChildBrowser. InAppBrowser does essentially the same thing, aside from missing a button to open in Safari.
Problem
The existing app's remote webpages include the Cordova JS (as well as that for the ChildBrowser plugin) and it works fine for opening links in the sub browser.
My test Cordova 2.7 app doesn't seem to load the Cordova JS correctly when it's being loaded from a remote web page.
I tried using this exact same HTML on the embedded start page and a remote start page:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript" src="http://mydomain.com/mobile/cordova-2.7.0.js"></script>
</head>
<body>
<script>
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
alert("Ready!!");
}
</script>
</body>
</html>
To test this as the embedded start page, I put this line in config.xml:
<content src="index.html" />
When I run the app, I promptly get the "Ready!" alert.
To test this as the remote start page (I'm aiming to link to the remote page in the final app, I am just using it as the start page for testing. The result is the same if I link from the embedded page.), I put this line in config.xml:
<content src="http://mydomain.com/mobile/index.php" />
When I run the app, I just get the blank screen and no alert.
Further, in cordova-2.7.0.js L. 6255, I changed
console.log('deviceready has not fired after 5 seconds.');
to
alert('deviceready has not fired after 5 seconds.');
With that change, running the app using the remote start page causes the blank page, and then after five seconds, I get the alert "deviceready has not fired after 5 seconds.". So this tells me Cordova JS is not starting correctly. Needless to say, I can't get InAppBrowser to launch links in the sub browser on the remote site, but I can get it working just fine on the embedded start page.
Anyone have any ideas of where to go from here? This is a pretty simplistic example, so I'm assuming this is a Cordova settings problem or a change in the functionality. I appreciate any thoughts, thanks!
Yes, something broke in 2.7 - related to our cordova-cli work. See: https://issues.apache.org/jira/browse/CB-3029
The fix is to add an empty file called "cordova_plugins.json" in your root folder.
I had a similar problem relating to upgrading to Cordova 2.7. However my problem was all my console.logs stopped firing when running the app. I couldn't figure out why for the life of me this was happening. I thought it was because I upgraded jquery.mobile. That wasn't it. I then thought it was an .htaccess issue, that wasn't it either. It turns out, it was Cordova 2.7 that was causing this problem.
I did try adding the .json file on my server, that did not fix the issue.
The fix was going into the 2.7 source and commenting out the following code:
/*comment out this as it is breaking console.logs
var xhr = new context.XMLHttpRequest();
xhr.onload = function() {
// If the response is a JSON string which composes an array, call handlePluginsObject.
// If the request fails, or the response is not a JSON array, just call finishPluginLoading.
var obj = this.responseText && JSON.parse(this.responseText);
if (obj && obj instanceof Array && obj.length > 0) {
handlePluginsObject(obj);
} else {
finishPluginLoading();
}
};
xhr.onerror = function() {
finishPluginLoading();
};
xhr.open('GET', 'cordova_plugins.json', true); // Async
xhr.send();
*/
Replace entire block with a call to the following function:
finishPluginLoading();
My logs are now working again. Only took me 3 days scratching my head.
Hope this helps someone with a similar problem.
If you embed Cordova in the external web page, there will be no way to open the InAppBrowser from within your hybrid app, so Cordova will not be able to load. This is because the InAppBrowser requires Cordova to be fully loaded and initialized before it can be used to fetch a remote page. You need to use your HTML page that you have, with the <script type="text/javascript" src="http://mydomain.com/mobile/cordova-2.7.0.js"></script> as the main entry point for your app. Then you can use the InAppBrowser to open up your remote page. (You could probably do this in the onDeviceReady(), not sure if it would "flash" the page first though.) I don't think the remote page should have any Cordova code in it at all. I'm not sure if it would be possible to even interact with Cordova from the remote page due to the Same Origin Policy (probably you could use features of the InAppBrowser to inject "bridge" code though to get around this.)
As Shazron mentioned the problem is the issue with the file"cordova_plugins.json".
To solve the problem not changing the code you can create the "cordova_plugins.json" file in the root folder and insert a content between quotation marks inside this file.
Mine for example has the following content:
"Just a dummy file required since Cordova 2.6.0"
create a file cordova_plugins.json that contains {}. then go to cordova-2.7.0.js and comment this line require('cordova/channel').onNativeReady.fire(); then when development done, add it back
Like me if you are using Cordova 5.1.1 and want to access native functionality after redirect then copy cordova.js, cordova_plugins.js and plugins folder which is at \platforms\platform_name\assets\www\ and put them on server, finally reference cordova.js inside your html. After every plugin add make sure to update these files and folder.

Categories