I have a weird network request in my page, which refers to JavaScript files, which I removed from every html file earlier. Cache is cleared and there is no single reference to be found in the source html and the JavaScript files. For fixing that and also out of general curiosity I would like to know if there is a simple way to find out where a request was triggered, preferably using the chrome-devtools.
Update:
Thanks to jaredwilli I found the initator column under the network-tab. However this only shows Other. What I would like to know, is the (html or javascript) file where those Requests have been triggered.
On the Network panel, you can determine what the initiator of a request was by viewing the Initiator column. It gives you the file, line number and type of resource it was, either Script or something else.
I'm completely new to JavaScript and D3.js. I have done some work in recent days, like making appropriate json object for the graph, and wanted to know how to get this example running in particular. Any direction to appropriate links would be great, though I would prefer to get an answer in the form of any missing tags or any details I need to take care of.
Note: I have to run it locally, not on server-client model.
Update: I have done it a lot of times what Bill answered, it didn't work. So I tried again and I opened the console in browser to check for any errors. Got this:
Failed to load resource: file://d3js.org/d3.v3.min.js
net::ERR_FILE_NOT_FOUND
index.html:23 Uncaught ReferenceError: d3 is not defined
The point is that you cannot access files on your computer from javascript using file:// (think that people could access all your file...).
So you have to use <script src="address/d3.js"></script> here, address correspond to the address of your server (http://domain.com or http://localhost) or the relative path.
For example, you can download d3.js next to your html file (same folder) and just type <script src="d3.js"></script>
Hope this helps
You can do the following:
Go to https://gist.github.com/mbostock/4062045
Click on the Raw button next to index.html
Copy everything and paste it into a file on your computer called index.html
Go back and click on the Raw button next to the .json file
Copy everything and paste it into a file on your computer called miserables.json (make sure this file is in the same folder as index.html)
Double click on index.html, it should open in your browser
I am administrating a web page were we have an HTML dokument linking to PDF-files. The PDF-files gets updated from time to time, but we don't want to change the file names. This means that the users get old cached copies of the files, and have to refresh the files manually in order to get the newest file.
I added the following code to the links:
onClick="this.href=this.href.split('?')[0]+'?'+new Date().getTime()">
This solved the problem were the users got old files, but introduced a problem were the user needs to load PDFs even though they have not been updated. This causes more server load, and longer wait times for the users. Is it possible to get a similar code were the script checks a hash or the file size of the target file and adds that to the URL behind the questionmark? If this is possible I would overcome all my problems.
I dont know where you got access to but i assume you can use php.
So you should append an md5 (generated by md5_file()) as parameter to your string. The parameter will only change, if you upload a new pdf (mtime() will have the same effect)
If this has been asked before, I apologize but this is kinda of a hard question to search for. This is the first time I have come across this in all my years of web development, so I'm pretty curious.
I am editing some HTML files for a website, and I have noticed that in the src attribute of the script tags that the previous author appended a question mark followed by data.
Ex: <script src="./js/somefile.js?version=3.2"></script>
I know that this is used in some languages for value passing in GET request, such as PHP, but as I far as I ever knew, this wasn't done in javascript - at least in calling a javascript file. Does anyone know what this does, if anything?
EDIT: Wow, a lot of responses. Thanks one and all. And since a lot of people are saying similar things, I will post an global update instead of commenting everyone.
In this case the javascript files are static, hence my curiosity. I have also opened them up and did not see anything attempt to access variables on file load. I've never thought about caching or plain version control, both which seam more likely in this circumstance.
I believe what the author was doing was ensuring that if he creates version 3.3 of his script he can change the version= in the url of the script to ensure that users download the new file instead of running off of the old script cached in their browser.
So in this case it is part of the caching strategy.
My guess is it's so if he publishes a new version of the JavaScript file, he can bump the version in the HTML documents. This will not do anything server-side when requested, but it causes the browser to treat it as a different file, effectively forcing the browser to re-fetch the script and bypass the local cache of the file.
This way, you can set a really high cache time (like a week or a month!) but not sacrifice the ability to update scripts frequently if necessary.
What you have to remember is that this ./js/somefile.js?version=3.2 doesn't have to be a physical file. It can be a page which creates the file on the fly. So you could have it where the request says, "Hey give me version 3 of this js file," and the server side code creates it and writes it to the output stream.
The other option is to force the browser to not cache the file and pull down the new one when it makes the request. Since the URI changed, it will think the file is completely new.
A (well-configured) web server will send static files like JavaScript source code once and tell the web browser to cache that file locally for a certain period of time (could be a day, a week, a month, or longer). When the browser sees another request for that same file, it will just use that version instead of getting new code from the server.
If the URL changes -- for example by adding a query string -- then the browser suspects that its cached version is no good and gets a new one. As such, the ? helps developers say "Oops, I changed this file, make sure the browser gets a new copy."
In this case it's probably being used to ensure the source file isn't cached between versions.
Of course, it could also be used server side to generate the javascript file, without knowing what you have on the other end of the request, it's difficult to be definitive.
BTW, the ?... portion of the url is called the query string.
this is used to guarantee that the browser downloads a new version of the script when available. The version number in the url is incremented each time a new version is deployed so that the browser see it as a different file.
Just because the file extension is .js doesn't mean that the target is an actual .js file. They could set up their web server to pass the requested URL to a script (or literally have a script named somefile.js) and have that interpret the filename and version.
The query string has nothing to do with the javascript. Some server side code is hosting up a different version depending on that querystring it appears.
You should never assume anything about paths in a URL. The extension on a path in a URL doesn't really tell you anything. URLs can be completely dynamic and served by some server side code or can rewritten in web servers dynamically.
Now it is common to add a querystring to urls when loading javascript files to prevent client side caching. If the page updates and references a new version of the script then the page can bust through and cause the client to refresh it's script.
I have some javascript that looks like this:
$('.resultitem').click(function(event){
alert('check this gets called');
location.href='viewinfo/'+$(this).attr('rel');
});
this code works fine on my local machine but after uploading to the server it doesn't seem to get called at all. Can anybody help me understand why?
UPDATE: As mentioned below this was caused by a script error higher up. While debugging with firebug, I noticed on the server that in the net tab a GET jquery.cookie.js failes with a code of 406 not acceptable.
I had to rename to jquerycookie.js to keep this particular hosting provider happy. I did a little more research and this could be due to the following:
"anything with .cookie. in it triggers an Apache mod_security warning, stopping the file from being served, effectively making this unable to work"
Are you including your JavaScript files using Cake's HTML helper? For example:
echo $this->Html->script(array('jquery-1.4.3.min'));
Note that following Cake's conventions, I've left off the .js file extension. In my experience, this has created problems where the production server thinks that .min is the file extension and attempts to load a nonexistent file called jquery-1.4.3.min, which means jQuery isn't loaded and therefore the snippet you've posted would fail.
I'm not sure if this is how you're loading your scripts, but in general it's safer to use the entire file name, like so:
echo $this->Html->script(array('jquery-1.4.3.min.js'));