|
|
html代码:: {& ~: I0 P5 h/ V& U b1 Z, j4 P
- <html> 4 A5 P2 N: z" t" W! ] F1 U
- <head> , ]) E, d+ D( a( Z+ ?! Y
- <title>combine_javascript example</title> ! a S" E3 e* ~
- <script src="js1.js"></script> " w& L9 q6 s! N. [$ L u
- <script src="js2.js"></script>
! G9 N: l, s8 ~; g9 t2 o0 [$ _3 Z - </head>
. S/ ]) H. E9 U/ c% s - <body>
8 M% O% h k/ @ - Hello, PageSpeed! * V( i) t7 e: @. @2 V7 F
- </body> 7 c$ I" w8 w8 [ u: ~ Q! V2 \
- </html>
复制代码 js1.js代码为:
1 x! n p% h( {! c% U9 {1 ~, W- D& c- function logText(message) { 6 k8 @2 Q+ T! x9 `% d _# ?/ p
- document.body.appendChild(document.createTextNode(message));
& {' X; u5 T7 v1 y! d0 K1 T' \8 K - document.body.appendChild(document.createElement("br"));
- n' a/ H* E) b4 D& F - }
复制代码 js2.js代码为:* G5 J' M* S" L- B
- window.onload = function() {
8 R9 b7 X& v& |5 M* l# Z - logText("Application started.");
2 Q$ l4 M7 H9 q- P/ M7 V8 U - logText("Library operation confirmed.");
5 Q+ z7 c% n2 g' Z7 Y1 [% S - }
复制代码 合并后的html代码:, B! ]1 _( N8 R! b0 a6 D
- <html>
1 R) j2 I0 z+ k4 T" ]. k - <head> ; _' K/ L8 m s
- <title>combine_javascript example</title>
$ t4 H- t# I# h3 y - <script src="js1-js2.js"></script>
. `' ? p8 t r6 f p) U - <script>eval(mod1);</script> <!-- 这里使用了eval()函数 //-->
- F( n0 h& A/ ]8 Z9 g! u# F3 |& A - <script>eval(mod2);</script> <!-- 这里使用了eval()函数 //--> 6 r: m( W+ L' \* n$ N. {8 t8 U
- </head>
0 m! ^) G& f$ j$ G - <body> * l: ]) a# S0 w( \( ^4 V$ Y
- Hello, PageSpeed! % u/ D* f! g$ K) a
- </body> % D( \/ F& V/ u
- </html>
复制代码 & T% |& C' G r5 S5 V# S, q) R/ b
0 O- e/ z3 `% p
|
|