Improve your skills

June 30, 2016

Place Scripts at the bottom of your page to Load Fast

Our primary goal is to make the web page load as quickly as possible for the user. When loading a script, the browser can't continue on until the entire file has been loaded. Thus, the user will have to wait longer before noticing any progress.

If you have JS files whose only purpose is to add functionality.

for example, After a button is clicked -- Go ahead and place those files at the bottom, just before the closing body tag. This is absolutely a best practice to boost your web page.

...
...
<p>The page load as quickly as possible.</p>
<script type="text/javascript" src="js/firstjs.js"></script>
<script type="text/javascript" src="js/secondjs.js"></script>
</body>
</html>






June 17, 2016

How to Show Alternate Image if Source Image is Not Found

The simple way to solve the problem-

By set the another image path in onError attribute of image, we resolve the problem. When the source image is not found then onError event fire and then it change source with another image. Use image tag described as below-

<img src="imageNotFound.jpg" alt="Image not found" onError="this.src='alternateImage.jpg';" />

If the alternate image is also not found then the browser will be go in an endless loop. onerror itself generates an error. To avoid endless loop, remove the onError from it at once.

<img src="imageNotFound.jpg" alt="Image not found" onError="this.onerror=null; this.src='alternateImage.jpg';" />

By calling this.onerror=null; 
It will remove the onError then try to get the alternate image and second time onError not call. 

Subscribe for Latest Update

Popular Posts