|
html代码:
) R5 H, q6 o# a _ _- <html> 7 w* N% J" Z+ T) i5 B& G
- <head> 8 F; g' T2 ^( @* E! y
- <title>combine_javascript example</title>
7 h3 Z7 t4 U$ B - <script src="js1.js"></script> # S1 f+ N1 u5 ~) B1 V' A
- <script src="js2.js"></script> , z/ v/ W1 R4 N; u! _. E2 |
- </head>
E% a$ e& R; }9 c' M, g - <body>
: X4 k! Y9 r) u) c) d1 {7 N - Hello, PageSpeed!
L& `( e1 i( k2 Y - </body>
p7 H+ N: E: k - </html>
复制代码 js1.js代码为:: D0 j. P" y3 {6 F4 |# {( r
- function logText(message) { 0 v& E0 u- X7 M7 E& m7 o. l
- document.body.appendChild(document.createTextNode(message));
, T9 @' \8 K* l( H G }& \ - document.body.appendChild(document.createElement("br"));
8 A3 b6 u# D4 T! r - }
复制代码 js2.js代码为:0 g' g9 Y" C3 G. H$ f6 X
- window.onload = function() { . L: e& f. N) U7 W' y
- logText("Application started."); 3 A0 A6 ]! _4 T
- logText("Library operation confirmed."); & i l" h& t: Z7 o. C3 U
- }
复制代码 合并后的html代码:
" k/ u) h) }7 w0 H& I+ |- <html> ' l: x/ ?) K# t6 M
- <head>
R0 _9 A4 J' I& z - <title>combine_javascript example</title> 3 A+ S3 I! R1 m+ i' s
- <script src="js1-js2.js"></script>
+ I4 e; Y" ]! S - <script>eval(mod1);</script> <!-- 这里使用了eval()函数 //-->
6 }2 V9 X( p. F* S$ x" }1 n - <script>eval(mod2);</script> <!-- 这里使用了eval()函数 //--> 8 A8 g: i, B1 N$ k- \
- </head> . V8 a0 h2 R3 g& {8 h7 G
- <body>
) Y0 Q2 B& W5 F - Hello, PageSpeed! % O0 `8 m1 ^9 l' |/ _
- </body>
- Z, ~' P; S$ ^1 A" B. h; \( Z$ R1 c6 F - </html>
复制代码
0 B. U% J* ?4 V9 |+ b9 u; X: o8 o
|
|