So what does a fast website feel like compared to a slow one? Let's take a look at an example. The golden rule of page performance is to make these files smaller. The files on your webpage are getting bigger. It’ gone up, but only by 16 and not at the same rate as page weight. These requests to files like CSS, javascript, images, etc are not going up at the same rate. HTTP Archive also tracks the number of requests sent from a page. With some pages creeping up above 7mb and it’s not that the sites have more files. In July 2019 the average size was under 2mb. The size of pages on the web is increasing. HTTP Archive has been tracking the page weight of sites since 2010 and there is a clear trend. Here we discuss how does minify work in JavaScript along with the advantages and examples.Websites are getting larger. from the source code to reduce the size of the file and improve the performance of the website and improves the accessibility. JavaScript minify is used to remove unnecessary white spaces, line breaks, block delimiters, comments, etc. ĭocument.getElementById("id1").innerHTML = "First Paragraph" ĭocument.getElementById("id2").innerHTML = "Second Paragraph" Įxplanation: As you can see in the above code all the empty spaces and blank space removed and we can see how much gain we got from initial size to final size. So minified JavaScript file will remove all these characters in the source code. The unnecessary characters mean white spaces, line breaks, block delimiters, comments, etc. Therefore it improved the browser website speed and accessibility, so it helps the search engine ranks moving up. When the user requests any web page then instead of sending actual JavaScript or HTML or CSS full version file, if we sent a minified version file then it results in faster response time and lower bandwidth cost. Minify in JavaScript is used to removes the unnecessary characters in our JavaScript or HTML or CSS source code to reduce the file size and make file to load faster than as before minifying. Example #7 – InnerHTML JavaScriptĬhanging paragraph content based on Id property Var numberArray= //line2ĭocument.write("Before adding the elements the array is=>"+numberArray+"") //line3ĭocument.write("After adding the elements with unshift function the array is=>"+ numberArray +"") //line5Įxplanation: As you can see in the above code all the empty spaces and blank space removed and we can see how much gain we got from initial size to final size. Example #6 – Unshift Array HTML and JavaScript Example #4 – Factorial JavaScriptĭocument.write(factorial(5)) //recursive function callĮxplanation: As you can see in the above code all the empty spaces and blank space removed and we can clearly seen how much gain we got from initial size to final size. Example #3 – Odd Sum JavaScriptĭocument.write(oddSum(10)) //recursive function callĮxplanation: As you can see in the above code all the empty spaces and blank space removed and we can see how much gain we got from initial size to final size. Example #2 – Even Sum JavaScriptĮxplanation: As you can see in the above code all the empty spaces and blank space removed and we can clearly seen how much gain we got from initial size to final size. console.log(naturalSum(10)) //display the output in browser consoleĭocument.write(naturalSum(10)) //display the output in the browser directly as like html pageĮxplanation: As you can see in the above code all the empty spaces and blank space removed and we can see how much gain we got from initial size to final size. Examples of JavaScript MinifyĪll the below examples I have used online compiler. Explanation: As you can see in the above after minifying the code all empty spaces and blank space are removed.
0 Comments
Leave a Reply. |