load.js
Lazy-load your JavaScript
How can I load an external JavaScript file using a bookmarklet? This would overcome the URL length limitations of IE and generally keep things cleaner.
Source: (StackOverflow)
I have an application with an EditText
element on the main view.
This means that when my application is loaded the soft keyboard appears per default.
I would like to be able to hide the keyboard on load,
so it does not show until i tap on the EditText
view.
How do i manage this?
Source: (StackOverflow)
i want to load css files on demand (by eg. running a xmlhttp request which returns the css files to be loaded) for example: style1.css, style2.css ..
so - is there a way in jQuery (or a plugin) to this:
- bulk-loading several files + adding all those css-files into the dom
- when finished loading: firing a callback (like alerting "all stylesheets are finished loaded!");
the idea is: loading html via xmlhttp, loading +adding required css-files,
then - after anything is finished, display that html.
any ideas? thx
Source: (StackOverflow)
I use dynamic script loading to reduce the duration of the initial page load. To ensure that the functions and objects defined by a script are accessible, I need to ensure that the script has been fully loaded.
I have developed my own Javascript library to this end, and thus did quite a lot of research on the subject, studying how it's done in different libraries.
During a discussion related to this issue, Kyle Simpson, the author of LABjs, stated that:
LABjs (and many other loaders) set
both "onload" and "onreadystatechange"
on all script elements, knowing that
some browsers will fire one, and some
will fire the other...
You can find an example of this in the current version of jQuery as of this writing, v1.3.2:
// Attach handlers for all browsers
script.onload = script.onreadystatechange = function(){
if ( !done && (!this.readyState ||
this.readyState == "loaded" || this.readyState == "complete") ) {
done = true;
success();
complete();
// Handle memory leak in IE
script.onload = script.onreadystatechange = null;
head.removeChild( script );
}
};
That's the state of the art, but during the analysis of a strange behavior in Opera 9.64, I came to the conclusion that, using this technique, the onload callback got fired too early.
I will post my own findings in answer to this question, and would like to gather further evidence and feedback from the community.
Source: (StackOverflow)
Are there any libraries for in-browser javascript that provide the same flexibility/modularity/ease of use as Node's require
?
To provide more detail: the reason require
is so good is that it:
- Allows code to be dynamically loaded from other locations (which is stylistically better, in my opinion, than linking all your code in the HTML)
- It provides a consistent interface for building modules
- It is easy for modules to depend on other modules (so I could write, for instance, an API that requires jQuery so I can use
jQuery.ajax()
- Loaded javascript is scoped, meaning I could load with
var dsp = require("dsp.js");
and I would be able to access dsp.FFT
, which wouldn't interfere with my local var FFT
I have yet to find a library that does this effectively. The workarounds I tend to use are:
coffeescript-concat -- it's easy enough to require other js, but you have to compile it, which means it is less great for fast development (e.g. building APIs in-test)
RequireJS -- It's popular, straightforward, and solves 1-3, but lack of scoping is a real deal-breaker (I believe head.js is similar in that it lacks scoping, though I've never had any occasion to use it. Similarly, LABjs can load and .wait()
does mollify dependency issues, but it still doesn't do scoping)
As far as I can tell, there appear to be many solutions for dynamic and/or async loading of javascript, but they tend to have the same scoping issues as just loading the js from HTML. More than anything else, I would like a way to load javascript that does not pollute the global namespace at all, but still allows me to load and use libraries (just as node's require does).
EDIT (MY ANSWER): Since writing this, I have extensively used RequireJS (which now has much clearer documentation). RequireJS really was the right choice in my opinion. I'd like to clarify how the system works for people who are as confused as I was:
You can use require
in everyday development. A module can be anything returned by a function (typically an object or a function) and is scoped as a parameter. You can also compile your project into a single file for deployment using r.js
(in practice this is almost always faster, even though require
can load scripts in parallel).
The primary difference between RequireJS and node-style require like browserify (a cool project suggested by tjameson) uses is the way modules are designed and required:
- RequireJS uses AMD (Async Module Definition). In AMD,
require
takes a list of modules (javascript files) to load and a callback function. When it has loaded each of the modules, it calls the callback with each module as a parameter to the callback. Thus it's truly asynchronous and therefore well-suited to the web.
- Node uses CommonJS. In CommonJS,
require
is a blocking call that loads a module and returns it as an object. This works fine for Node because files are read off the filesystem, which is fast enough, but works poorly on the web because loading files synchronously can take much longer.
In practice, many developers have used Node (and therefore CommonJS) before they ever see AMD. In addition, many libraries/modules are written for CommonJS (by adding things to an exports
object) rather than for AMD (by returning the module from the define
function). Therefore, lots of Node-turned-web developers want to use CommonJS libraries on the web. This is possible, since loading from a <script>
tag is blocking. Solutions like browserify take CommonJS (Node) modules and wrap them up so you can include them with script tags.
Therefore, if you are developing your own multi-file project for the web, I strongly recommend RequireJS, since it is truly a module system for the web (though in fair disclosure, I find AMD much more natural than CommonJS). Recently, the distinction has become less important, since RequireJS now allows you to essentially use CommonJS syntax. Additionally, RequireJS can be used to load AMD modules in Node (though I prefer node-amd-loader).
Source: (StackOverflow)
Possible Duplicate:
How do you stress test a web application?
Currently I have configured a project with cc.net, watin and nunit and now I want to do stress, load, and performance testing of my .net projects. Any idea which opensource tool should I use or cani achive it with same working tools and if yes then how?
Source: (StackOverflow)
Is there a way to capture when the contents of an iframe have fully loaded from the parent page?
Source: (StackOverflow)
I am trying to make a Java tool that will scan the structure of a Java application and provide some meaningful information. To do this, I need to be able to scan all of the .class files from the project location (JAR/WAR or just a folder) and use reflection to read about their methods. This is proving to be near impossible.
I can find a lot of solutions based on URLClassloader that allow me to load specific classes from a directory/archive, but none that will allow me to load classes without having any information about the class name or package structure.
EDIT:
I think I phrased this poorly. My issue is not that I can't get all of the class files, I can do that with recursion etc. and locate them properly. My issue is obtaining a Class object for each class file.
Source: (StackOverflow)
It's been on the cards for a while, but now that Amazon have released Elastic Load balancing (ELB), what are your thoughts on deploying this solution for a high-traffic web application?
Should we replace HAProxy or consider ELB as a complimentary service in front of HAProxy?
Source: (StackOverflow)
Are there any benefits to omitting the closing body and html tags?
Why is the google.com homepage missing the closing body and html tags?
edit - with regards to bandwidth, it's an extremely small amount, really. Say 10 million hits @ roughly 10 bytes saved ~ 100 mb only... Are there reasons other than bandwidth?
edit 2 - and nope, google (yahoo, microsoft, and others) are not w3-validator compliant... when it comes to bandwidth-saving en mass vs w3-compliance, I guess the latter's good for the sacrificing?
Source: (StackOverflow)
Shortly, I have an NSDictionary
with urls for images that I need to show in my UITableView
. Each cell has a title and an image. I had successfully made this happen, although the scrolling was lagging, as it seemed like the cells downloaded their image every time they came into the screen.
I searched for a bit, and found SDWebImage
on github. This made the scroll-lagg go away. I am not completely sure what it did, but I believed it did some caching.
But! Every time I open the app for the first time, I see NO images, and I have to scroll down, and back up for them to arrive. And if I exit the app with home-button, and open again, then it seemes like the caching is working, because the images on the screen are visible, however, if I scroll one cell down, then the next cell has no image. Until i scroll past it and back up, or if I click on it. Is this how caching is supposed to work? Or what is the best way to cache images downloaded from the web? The images are being updated rarily, so I was close to just import them to the project, but I like to have the possibility to update images without uploading an update..
Is it impossible to load all the images for the whole tableview form the cache(given that there is something in the cache) at launch? Is that why I sometimes see cells without images?
And yes, I'm having a hard time understanding what cache is.
--EDIT--
I tried this with only images of the same size (500x150), and the aspect-error is gone, however when I scroll up or down, there are images on all cells, but at first they are wrong. After the cell has been in the view for some milliseconds, the right image appears. This is amazingly annoying, but maybe how it has to be?.. It seemes like it chooses the wrong index from the cache at first. If I scroll slow, then I can see the images blink from wrong image to the correct one. If I scroll fast, then I believe the wrong images are visible at all times, but I can't tell due to the fast scrolling. When the fast scrolling slows down and eventually stops, the wrong images still appear, but immediately after it stops scrolling, it updates to the right images. I also have a custom UITableViewCell
class, but I haven't made any big changes.. I haven't gone through my code very much yet, but I can't think of what may be wrong.. Maybe I have something in the wrong order.. I have programmed much in java, c#, php etc, but I'm having a hard time understanding Objective-c, with all the .h
and .m
...
I have also `
@interface FirstViewController : UITableViewController{
/**/
NSCache *_imageCache;
}
(among other variables) in FirstViewController.h
. Is this not correct?
Here's my cellForRowAtIndexPath
.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"hallo";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSMutableArray *marr = [hallo objectAtIndex:indexPath.section];
NSDictionary *dict = [marr objectAtIndex:indexPath.row];
NSString* imageName = [dict objectForKey:@"Image"];
//NSLog(@"url: %@", imageURL);
UIImage *image = [_imageCache objectForKey:imageName];
if(image)
{
cell.imageView.image = image;
}
else
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSString* imageURLString = [NSString stringWithFormat:@"example.com/%@", imageName];
NSURL *imageURL = [NSURL URLWithString:imageURLString];
UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:imageURL]];
if(image)
{
dispatch_async(dispatch_get_main_queue(), ^{
CustomCell *cell =(CustomCell*)[self.tableView cellForRowAtIndexPath:indexPath];
if(cell)
{
cell.imageView.image = image;
}
});
[_imageCache setObject:image forKey:imageName];
}
});
}
cell.textLabel.text = [dict objectForKey:@"Name"];
return cell;
}
Source: (StackOverflow)
Can anyone let me how can I make selenium wait until the time the page loads completely? I want something generic, I know I can configure WebDriverWait and call something like 'find' to make it wait but I don't go that far. I just need to test that the page loads successfully and move on to next page to test.
I found something in .net but couldn't make it work in java ...
IWait<IWebDriver> wait = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(30.00));
wait.Until(driver1 => ((IJavaScriptExecutor)driver).ExecuteScript("return document.readyState").Equals("complete"));
Any thoughts anyone?
Source: (StackOverflow)
I'm writing an application for iPad using PhoneGap and I would like to load an external URL without triggering Safari or using internal web browser like ChildBrowser.
I'm using the PhoneGap iPad/iPhone sample project and I tried different approaches. In the onBodyLoad() function I added:
window.location.href('http://www.wordreference.com');
but this line opens the link using a new Safari window.From that point is not possible to come back in PhoneGap
Afterwards, I tried with an AJAX request substituting the content of the page using document.write
function loadHTML(url, timeout) {
if (timeout == undefined)
timeout = 10000;
var req = new XMLHttpRequest();
var timer = setTimeout(function() {
try {
req.abort();
} catch(e) {}
navigator.notification.loadingStop();
},timeout);
req.onreadystatechange = function() {
if (req.readyState == 4) {
if (req.status < 300) {
clearTimeout(timer);
var html = req.responseText;
//just a debug print
alert(html);
document.write(html);
}
navigator.notification.loadingStop();
delete req;
}
};
req.open('GET', url, true);
req.send();
}
Now, calling from inside onBodyLoad():
loadHTML('http://www.wordreference.com',10000);
Opens the link in the PhoneGap Container,which is fine. The point is that I want to load a dynamic page written in Python
loadHTML('http://www.mysite.com/cgi-bin/index.py',10000)
At this point Safari is not called but a black page in the PhoneGap container is displayed!!
I want to point out that the link is perfectly working if I type it in Safari( I cannot report it for privacy issues).
Could be it a problem related to some kind of needed permission???
I found something similar relative to PhoneGap for BlackBerry and the proposed solution was to modify a config.xml file with
<access subdomains="true" uri="http://www.mysite.com/" />
I tried to add this tag directly in my index.html but it doesn't work.
Is there any similar approach for iPhone??
Thanks a lot
Source: (StackOverflow)
I have some R scripts, where I have to load several dataframe in R as quickly as possible. This is quite important as reading the data is the slowest part of the procedure. E.g.: plotting from different dataframes. I get the data in sav (SPSS) format, but I could transform it to any format as suggested. Merging the dataframes is not an option unfortunately.
What could be the fastest way to load the data? I was thinking of the following:
- transform from sav to binary R object (Rdata) in the first time, and later always load this, as it seems a lot quicker than
read.spss
.
- transform from sav to csv files and reading data from those with given parameters discussed in this topic,
- or is it worth setting up a MySQL backend on localhost and load data from that? Could it be faster? If so, can I also save any custom
attr
values of the variables (e.g. variable.labels from Spss imported files)? Or this should be done in a separate table?
Any other thoughts are welcome. Thank you for every suggestion in advance!
I made a little experiment below based on the answers you have given, and also added (24/01/2011) a quite "hackish" but really speedy solution loading only a few variables/columns from a special binary file. The latter seems to be the fastest method I can imagine now, that is why I made up (05/03/2011: ver. 0.3) a small package named saves to deal with this feature. The package is under "heavy" development, any recommendation is welcome!
I will soon post a vignette with accurate benchmark results with the help of microbenchmark package.
Source: (StackOverflow)