O'Reilly logo

PhantomJS Cookbook by Rob Friesel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Blocking CSS from downloading

In this recipe, we will demonstrate how to use the onResourceRequested callback to block files from downloading. Although we can use this technique to block any resource type, we will specifically be blocking CSS here; this can be useful to generate snapshots of how our sites look when the CSS fails.

Getting ready

To run this recipe, we will need a script that loads a web page; that web page must use CSS so that we can block the style sheet resources.

The script in this recipe is available in the downloadable code repository as recipe11.js under chapter03. If we run the provided example script, we must change into the root directory for the book's sample code.

Lastly, the script in this recipe runs against the demo site ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required