how to clear my clients cache next time they log in

后端 未结 6 1794
萌比男神i
萌比男神i 2021-01-11 18:27

I have an application running on hostgator. When I make changes to the js files my users don\'t see the changes until they clear their cache. Is this the only option to pu

6条回答
  •  南方客
    南方客 (楼主)
    2021-01-11 18:54

    A simple trick I use sometimes is to add some dummy parameters to the path of the JavaScript/CSS file. The browser will essentially see a different URL and will not use it's cached version.

    $jsFile = '/js/myFile.js';                // probably cached
    $jsFile = '/js/myFile.js?r='.time();      // won't ever be cached
    

    You can't really clear the clients cache, but you can trick the clients browser into thinking that this is the first time it is seeing this file and it will download it again.

    Don't forget to disable this once you have arrived at a stable version. Caching files is a great way to speed up an application's load time.

提交回复
热议问题