...body of page...




Example 1mypage.html with JavaScript code

We replace the JavaScript code with an instruction for the browser to go and grab the code from a separate file. The new page will look like this.



My Title< itle><br><script src="codepage.js"></script><br></head><br><body onLoad="helloWorld()"><br><br> ...body of page...<br><br></body><br></html><br><br>Example 2mypage.html with JavaScript code offloaded<br><br>Note the addition of the "src" attribute to the SCRIPT tag. The value assigned to that attribute is the name of the external file that contains the JavaScript code. Typically, these external files will be given the filename extension ".js" to indicate that they contain JavaScript code. Note also that there are both <script> and </script> tags here, even though there is nothing between those tags.<br><br>A new page is then created that holds the code that was formerly held in the SCRIPT tags. We will call it "codepage.js", and it looks like this.<br><br>function helloWorld(){<br> alert("Hello, World!");<br> return;<br>}<br><br>Example 3codepage.js includes only JavaScript code<br><br>This new file doesn't need any kind of HTML markup. It contains only the code that was originally held between the SCRIPT tags.<br><br>Style Sheet problem<br><br>In addition to JavaScript code, Style Sheet code can cause complications for Search Engines when it is put into a web page. For the same reasons as JavaScriptmoving the important content further down the page, and diluting the keyword densityit is important to move Style Sheet code off of the page as well. <br><br>Style Sheet solution<br><br>The thought behind removing Style Sheet information from a page is very similar to that of offloading JavaScript; the syntax to do so is different.<br><br>The original page, "mypage.html", may look something like this.<br><br><HTML><br><HEAD><br><TITLE>My Title





...body of page...




Example 4mypage.html with style sheet code

We want to move this code into a separate file, so we remove it from the original page, and add a link to point to the separate file that now holds the Style Sheet code.



My Title





...body of page...

0 ความคิดเห็น