Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
John McEleney
/
casperjs
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
63f5f3be
...
63f5f3be8fbc6db1f80adc1fc9fde85fffa38b85
authored
2012-05-27 09:48:13 +0200
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fixes #122 - allow downloads to be triggered by more than just GET requests
1 parent
ab761929
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
0 deletions
samples/pageweight.js
samples/pageweight.js
0 → 100644
View file @
63f5f3b
/**
* Check out sizes of resources loaded on a given web page.
*
* Usage:
* $ casperjs samples/pageweight.js <url>
*/
var
casper
=
require
(
'casper'
).
create
();
var
size
=
0
;
function
kb
(
size
)
{
return
Math
.
round
(
size
/
1024
*
100
)
/
100
;
}
casper
.
on
(
'resource.received'
,
function
(
r
)
{
if
(
r
.
stage
!==
"end"
)
{
return
;
}
var
rSize
;
r
.
headers
.
forEach
(
function
(
h
)
{
console
.
log
(
h
.
name
);
});
if
(
r
.
bodySize
)
{
rSize
=
~~
r
.
bodySize
;
}
else
{
try
{
rSize
=
~~
r
.
headers
.
filter
(
function
(
h
)
{
return
h
.
name
.
toLowerCase
()
===
"content-length"
;
}).
pop
().
value
;
}
catch
(
e
)
{
// try actual content length
if
(
this
.
getCurrentUrl
()
===
r
.
url
)
{
rSize
=
casper
.
page
.
content
.
length
;
}
}
}
this
.
echo
(
r
.
url
+
': '
+
rSize
);
size
+=
rSize
||
0
;
});
casper
.
on
(
'load.finished'
,
function
(
status
)
{
this
.
echo
(
'Total: '
+
kb
(
size
)
+
'KB'
).
exit
();
});
casper
.
start
(
casper
.
cli
.
get
(
0
));
casper
.
run
(
function
()
{
});
Please
register
or
sign in
to post a comment