CasperJS simultaneous requests

casperjs

Solution

If you don't care about synchronizing behavior between all the URLs that you are opening, then you should start multiple instances of casper for each URL. Here is an example:

var casperActions = {
  href1: function (casper) {
    casper.start(address, function() {...});
    // tests and what not for href1
    casper.run(function() {...});
  },
  href2: function (casper) {
    casper.start(address, function() {...});
    // tests and what not for href2
    casper.run(function() {...});
  },
  ...
};

['href1', 'href2', ...].each(function(href) {
  var casper1 = require('casper').create();
  casperActions[href](casper);
});

Each instance would run independently of each other, but it would allow you to hit many URLs simultaneously.

Problem

Lets say I have an array of urls. I dont want to use thenOpen function . Since it waits for every previous url to be loaded and it decreases load time . ``` casper.each(hrefs,function(self,href){ self.thenOpen(href,function(){ }); self.then(function(){ // Selectors }); ``` }); What methods would u use to spend much less compared to above method ? Would it be efficient to create multiple instances store in the db and then fetch ... but this is alot of headache . And also would like u also to answer in general would I have problems when I run multiple instances of the same js file simultaneously ?

Original source