Created
July 5, 2015 11:46
-
-
Save pcolazurdo/f9a0218668940b5682c6 to your computer and use it in GitHub Desktop.
PhantomJS script for detecting Content-Encoding of JS resources (for httpd diagnosis)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var page = require('webpage').create(), | |
| system = require('system'), | |
| address; | |
| if (system.args.length === 1) { | |
| console.log('Usage: netlog4.js <some URL>'); | |
| phantom.exit(1); | |
| } else { | |
| address = system.args[1]; | |
| page.onResourceRequested = function (req) { | |
| }; | |
| page.onResourceReceived = function (res) { | |
| if ( String(res.contentType).indexOf('javascript') >= 0 ) { | |
| var condition = false; | |
| console.log(res.url); | |
| res.headers.forEach( function(a,b) { | |
| if (a.name.indexOf('Encoding') >= 0) { | |
| console.log(a.value); | |
| if (a.value.indexOf('gzip') = -1 ) { | |
| console.log(JSON.stringify(res)); | |
| } | |
| } | |
| }); | |
| console.log('Condition'); | |
| }; | |
| }; | |
| page.open(address, function (status) { | |
| if (status !== 'success') { | |
| console.log('FAIL to load the address'); | |
| } | |
| phantom.exit(); | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment