html代码:
1 `7 e' w: l9 P S- <html>
0 c, f4 J& q, |/ t' z - <head> * L% z/ }% F/ r7 Z( D( i
- <title>combine_javascript example</title>
4 U2 S- s5 C+ e - <script src="js1.js"></script> ; P" K7 j. h* F6 x
- <script src="js2.js"></script>
0 l% `8 ]4 |5 m8 p7 a" p - </head>
, J# ]; H0 L% h7 ?8 Z% d - <body> a; n: H* O- Z9 p
- Hello, PageSpeed! 0 R) o2 P9 U P" z# f$ K. Z
- </body>
; d) e4 s" y, I' _) \ - </html>
复制代码 js1.js代码为:: k% h8 v, W' Y8 x6 X
- function logText(message) { $ |4 }" I8 _& { e& A
- document.body.appendChild(document.createTextNode(message));
& |2 a) l" B+ [6 s# k5 ?8 k - document.body.appendChild(document.createElement("br"));
+ ?; r# E+ l7 T: ?& W4 M: t! R - }
复制代码 js2.js代码为:
# O0 L' f, ~( S' M4 Z$ p- window.onload = function() { ! l; p g# w, p5 L6 I1 ~
- logText("Application started."); * Y: k3 k$ i- k
- logText("Library operation confirmed."); & r, P6 ~" x& f9 ~" q* c
- }
复制代码 合并后的html代码:: Y7 _ V9 t' S
- <html>
# e8 F9 L F5 `- w3 b+ N - <head>
+ U3 c) A; `; Y3 [; ]: P+ Z7 I - <title>combine_javascript example</title> & \3 x6 \. d% Q. F# f' j
- <script src="js1-js2.js"></script> , H( T, M( h4 X7 C8 a9 P
- <script>eval(mod1);</script> <!-- 这里使用了eval()函数 //-->
; w* k' s$ Y& J7 F" o) L - <script>eval(mod2);</script> <!-- 这里使用了eval()函数 //-->
8 A% d s! P5 b' l7 K1 V3 N8 r5 R/ v - </head> . U) R; {% P5 c" t" r& _3 k* ~
- <body>
" n8 A& K; g8 i. Q; _: u( { - Hello, PageSpeed! ! t6 c9 C4 t' q1 w
- </body>
! Z# P1 R" p! k1 V4 T% ? - </html>
复制代码 ( d& z' _2 R8 ]
2 V3 v( M% q6 | h" J" y. r |