External js file problems - javascript

I have an external js file with some simple functions. They work fine when in the aspx page. When they are in the external js file, I get an error on the dev machine that the function is not defined. After playing with this for two days in IE9, I tried it in FF and it worked fine. Then, it worked in IE9 too. I had a second site with the same problem. I checked it again and it didn't work in IE9, then checked it in FF, it worked, and then it continued to work in IE9. What could possible cause this?

Ultimately this depends on whether or not the file is being included in the page correctly via the <script> tag. I'd be surprised if one browser can resolve a bad reference and another one cannot, since it's ultimately the server's job to determine if a file path is correct or not. So check that your include mechanism is always including the file correctly. You can run a trace with Fiddler for example, and watch for any 404 errors when the browser requests scripts.
The other possibility is that the script itself is being included correctly, but it contains syntax or references that Firefox accepts as valid but IE9 doesn't. For example, a reference to console will bomb in some versions of IE but will work fine in Chrome. Check that your script is valid to begin with.

Related

Javascript works locally and on firefox, but shows up blank in the inspector on other browsers

I have a website I'm designing for class, and the javascript/jquery works perfectly in a local directory and on firefox (for some reason), but doesn't on other browsers. I'm using Opera to test this site. When I use Inspect Element and look at the .js file, it shows up completely blank for some reason, even though its contents look fine from cPanel. There are no error messages to track down the issue either.
I transferred my files using ftp with FileZilla, and I'm using bluehost as a web hosting service. All my html files are in the public_html directory in cPanel, and my javascript file is in a subdirectory called _js. CSS files are loading fine, I've seen similar posts saying both js and css aren't working which isn't the case here.
This is my html. I also tried putting it before </body> without any more luck either. I've also tried using multiple srcs to Jquery libraries copied from other forum posts with similar questions, thinking maybe its a dependent library issue, but still nothing.
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script type="text/javascript" src="_js/javascript.js"></script>
</head>
My javascript is set up as so
$(document).ready(function () {
I've tried putting this DOMContentLoaded before, after, and inside the document ready function.
document.addEventListener('DOMContentLoaded', init, false);
I'm at my wits end. I can't find anywhere else with this specific problem. I saw somewhere about how Firefox checks over the files multiple times, but I don't really understand how, nor do I know how to make other browser do it. I also don't know why the inspector just thinks its a blank js file. I didn't think hosting Javascript would be so tedious.

Chrome insists on keeping stale/old javascript code and won't reload the recent version

I'm doing some very simple web dev and using chrome's debugger. The included javascript never seems to update when I modify the source. I can delete the contents of the whole file and it still loads stale code (unless I restart chrome). If I remove permissions on the file, it notices and won't load the page but when replacing permissions the old code is back. This happens both when fetching via http and the local file directly. No amount of spamming reload or ctrl-F5 works. I've tried clearing and manually deleting the cache and even setting the don't cache option in the developer options. I don't think chrome's in local modifications mode but I can never tell (this "feature" is amazingly buggy if not sometimes quite desirable). I don't have this issue in firefox but specifically want to test chrome at the moment.
Has anyone seen this before? What are the common causes? What can I do to prevent this happening?
I'm running fedora 18 with google-chrome 31.0.1650.39-1 - and after noting a newer version - 32.0.1700.19-1. Both have the same issue.
I think ctl-shift-r does a "hard reload," ignoring any cache.
I normally get this problem with Dreamweaver, the new code refreshes fine in the dreamweaver window but when I wanna test on chrome it loads the old code. It generally just takes a couple refreshes for the code to catch up - I assumed the problem was because I was running the files off an appache server which could be causing the delay however it's still local

Unwanted JavaScript file in Firefox, NS_ERROR_XPC_BAD_CONVERT_JS

I don't know why but I get JavaScript error only in Firefox, also I see some unwanted JavaScript file in my page that I never referenced to them before.
What's this? Actually I want to know what's this unwanted JavaScript file in my page?
I found the answer, it's because of one FireFox extension that automatically included some external javaScript files to all of pages and it's prevent Firebug to work well.
Removing extension solved all problems.

JS Error in Internet Explorer

I'm getting "Object Expected JS error in IE 6 and 7. I'm not able to reproduce this always. The behavior is inconsistent. I'm using Dojo Charts in my JSP page. When this error occurs none of the Charts gets loaded.
I had a similar problem with IE before. That was a JS function was called before the JS file was loaded completely. We can see the JS file in the request, but that file is empty.
I wonder why IE is not taking the JS files from cache. It works perfectly in Mozilla.
Can some one suggest a better way to track such inconsistent JS errors?
thanks
You're dereferencing a variable which is undefined, but without an example, hard to say much beyond that.
(everything is an object in javascript so it's pretty much the only way to generate that error)
In Internet options in Advanced tab you can enable debugging.
IE has a lot of quirks that won't arise in other browsers. The best way to debug IE is to get a copy of Microsoft's Script Debugger, and you can launch it from IE to get a clearer idea of where the actual problem is. Script Debugger will halt execution at the problem line and show it in a separate window (IE locks up until you close Script Debugger, but you get a much better idea of what line is causing the problem).
See here for more: http://www.codestore.net/store.nsf/unid/DOMT-5UBUVW?OpenDocument
There's a link in the middle of that document that goes to MS Script Debugger, but here it is anyway.

Using Firebug Lite (1.2) would you use it in production sites?

I tried to use Firebug Lite (via the bookmarklet and also adding it to one of my web sites).
I seem to get the alert:
Unable to detect the following script "firebug-lite.js" ... if the
script has been renamed then please set the value of
firebug.env.liteFilename to reflect this change
Alot. Especially when I try to close the tab. This happens in Firefox, Camino and Safari.
What I'm wondering is, is this ready for use?, or do I need to copy the code, post it locally and hack it? I already checked the documentation, and it was pretty limited.
I was also looking at the mod dates and the site appears to have been relatively idle since mid-2008.
The javascript file rounds out at 77,305 bytes, so I would think you would not want to use it on a production site unless you were using a dynamic language and could output the script conditionally when you need to do debugging.
(i.e. http://www.somefakesite.com/page?debug=true)
As long as you're only including the file in the page when you are actually debugging, it probably doesn't matter where you pull the script from unless it doesn't work correctly, in which case you would have to modify and serve it yourself.

Categories