- SPLessons

Always get updated Js and Css files in your Project

Home > > Tutorial
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 [html] <!--dont include like below statement in your page--> <!--<script type="text/javascript" src="js/yourjsfile.js"></script>--> <div runat="server" id="jsDiv"> </div> [/html] [csharp] // 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; } [/csharp]

Step2 :
If your Project built on PHP use below Code

[html] <!--dont include like below statement in your page--> <!--<script type="text/javascript" src="js/yourjsfile.js"></script>--> [/html] [php] <?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>"; ?> [/php] Always get updated Js and Css files in your Project If you have any queries for above scenario please comment below.