Reputation: 1523
Why does PhantomJS require so much time to load pages than other modules like cURL and file_get_contents
?
I've tried loading google with PhantomJS as well as cURL. cURL took only 20-50ms to load, but PhantomJS took 730ms, even with load-images
option set to false
.
What may be the reason for slowness of PhantomJS?
I've tested the time difference inside page load's callback function, immediately.
Here is my code:
var page = require("webpage").create();
page.viewportSize = { width: 1024, height: 768 };
page.open('$url', function(status) {
console.log('PhantomJS load time:', Date.now() - start);
page.render('screenshot.png');
phantom.exit();
});
What methods I can use to improve the page load speed to maximum possible extent, in general or for PhantomJS?
Upvotes: 0
Views: 1302
Reputation: 61962
PhantomJS is a full browser (headless, but still a browser). A full browser with an empty cache needs to do many requests to get all page resources and wait until the page is rendered. You can use the --disk-cache=true
option to let PhantomJS cache some data for subsequent requests, but it will still be much much slower than cURL.
cURL makes only one request without rendering anything. Of course it's much faster, because it's not a browser.
Upvotes: 4