|
|
html代码:
/ v6 l, N* u# f# X; P8 M' N& b- <html>
* k9 g4 Q% f" R6 w0 B- p - <head> : P$ w6 A- ^- \( O2 X( e
- <title>combine_javascript example</title> + i; M# ~) V/ d0 P t
- <script src="js1.js"></script>
1 i* Q1 i1 N" Y' N2 d - <script src="js2.js"></script> + [: \) ^5 W+ H g% q/ K; l1 S
- </head> 5 X4 E' s5 S; M, S8 ?" Z" m% J: E7 s# F
- <body>
0 V n, T1 i. P! z4 k% r - Hello, PageSpeed!
0 J9 n. k: z, Z* V0 W) { - </body> * D0 x! v$ g# V2 S
- </html>
复制代码 js1.js代码为:; I t. g3 c4 x( `
- function logText(message) { - l; J$ R! W# T, N6 A+ i4 K! Z
- document.body.appendChild(document.createTextNode(message)); ) K/ t+ l) R4 V% P: G6 U3 b; b! I! _8 y
- document.body.appendChild(document.createElement("br"));
6 O' B. d( N' }# T9 P" D( K - }
复制代码 js2.js代码为:
% x' y- c* l- F- window.onload = function() {
6 F4 b3 q+ q7 G' C - logText("Application started.");
, i& i6 R- S' G! l3 ~ - logText("Library operation confirmed.");
2 R( D. s7 [# U Z6 _+ m - }
复制代码 合并后的html代码:" t9 s }" R" ]. T) e, c
- <html>
. @; |; W# ^: p - <head>
- h: s" H4 a& Z; l2 Y" q2 P5 ^ - <title>combine_javascript example</title>
$ s9 S$ B2 F, _0 L5 X - <script src="js1-js2.js"></script> 7 n2 E' p1 ~7 k _$ T$ t7 R3 L9 [9 a
- <script>eval(mod1);</script> <!-- 这里使用了eval()函数 //-->
, B1 i0 R! r! j) F% { - <script>eval(mod2);</script> <!-- 这里使用了eval()函数 //--> * [+ c6 N/ B' G7 A% c! D
- </head> ) C; B! }, t0 ?) e" a$ M
- <body> ! i/ W6 T0 O$ I- V0 [
- Hello, PageSpeed! + U% E0 B: E6 Z& g/ _2 y
- </body> 1 r& \4 Z! ~, h* Y$ Z
- </html>
复制代码
* `2 h' O; e7 B+ M4 ^: Z! y$ o. u4 a, l$ i2 g3 @
|
|