|
html代码:
/ H- v* E. C) B% ]# R4 V- L# ]- <html> * d% N/ R8 e+ d7 q. S) A7 W+ d- w
- <head>
: E/ u7 r0 z5 E3 G$ m - <title>combine_javascript example</title>
4 R/ D1 Z# M' M( ^ - <script src="js1.js"></script> 9 n+ ]' I! Z' y) Y
- <script src="js2.js"></script>
' r5 p1 |9 q) p9 x - </head>
) l' X: N4 b; w$ x! A2 H6 w( r; Y/ w - <body>
, T; i% E: R# s3 S3 a2 t - Hello, PageSpeed!
5 G( Y1 W' X( Z1 r& f - </body>
! ~9 n5 c1 G: v - </html>
复制代码 js1.js代码为:7 r! p9 w9 t9 j
- function logText(message) {
- {+ ~3 i% O" d: V3 ? - document.body.appendChild(document.createTextNode(message));
$ Z6 [! F- b# \" j( R/ D! v - document.body.appendChild(document.createElement("br"));
F! o, X" P1 v2 l# Z5 ~ - }
复制代码 js2.js代码为:6 y7 i4 I* G/ c5 y( J5 s9 i
- window.onload = function() {
* s( B g# W' Z5 X+ ?* Q - logText("Application started.");
& {* R+ Q+ \. }" S - logText("Library operation confirmed.");
2 b1 D4 V9 I" r1 j4 h - }
复制代码 合并后的html代码:' j' V( G6 L; G# A) i
- <html> ! u/ Q9 x' V* u9 r: W( _) _2 a
- <head> ( o# K% @/ B K3 ~, y/ Q( Q& d% p! ~
- <title>combine_javascript example</title> : P" w4 r/ G6 x- t
- <script src="js1-js2.js"></script>
1 C+ W7 G: u* u& B* V; ^ - <script>eval(mod1);</script> <!-- 这里使用了eval()函数 //-->
% _6 W4 r2 F0 p) Z/ b" A - <script>eval(mod2);</script> <!-- 这里使用了eval()函数 //-->
# J a9 O V# L: l" X! H3 w - </head>
# F- G: y3 T- p* F: H. ?% ^& H - <body> 6 M# a) r& R' _, b2 g. B( A6 C
- Hello, PageSpeed! 7 c( K: L3 o% @: G! {
- </body> 3 W1 k# d5 z- H" t \6 n
- </html>
复制代码
: w, ~% k9 T+ D6 w/ J( J& l: z8 }4 V8 _
|
|