- SPLessons

Always get updated Js and Css files in ...

SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Always get updated Js and Css files in your Project

 Always get updated Js and Css file in your Project 


Description :

If you are browsing any site repeatedly, for first time it will get updated files, from the next time it will take files from browser cache. If your updated your Js or Css file it will not get reflect in your site until you press Ctrl+F5 ( Server Side Refresh ) many times. This will create some issues to your site and to users.

To avoid this type of errors Just follow below steps to get always updated file Js or Css file in your Project.

 

 

 

Step1 :

If your Project built on .Net use below Code

// add this in your asp.net page


<!--dont include like below statement in your page-->
<!--<script type="text/javascript"  src="js/yourjsfile.js"></script>-->

<div runat="server" id="jsDiv">
</div>

// copy below code at server side in page load method
protected void Page_Load(object sender, EventArgs e)
        {
            // To load latest Js file every time
            long startTick = DateTime.Now.Ticks;
            string Jslink = "<script type='text/javascript' src='js/yourjsfile.js?id=" + startTick + "'></script>";
            jsDiv.InnerHtml = Jslink;

        }

Step2 :

If your Project built on PHP use below Code

<!--dont include like below statement in your page-->
<!--<script type="text/javascript"  src="js/yourjsfile.js"></script>-->

<?php 

$Timevariant=microtime(); 

// with below statement everytime the browser will consider as a new js file
echo "<script type='text/javascript'  src='js/yourjsfile.js?".$Timevariant."'></script>";
 ?>

Always get updated Js and Css files in your Project

If you have any queries for above scenario please comment below.