How do Facebook, Google and other large applications do their CSS and JavaScript files?

前端 未结 2 1465
醉梦人生
醉梦人生 2021-02-01 08:12

Facebook: http://static.ak.fbcdn.net/rsrc.php/v1/yh/r/u2OL99TwlfU.css
Google: http://ssl.gstatic.com/gb/js/sem_cf9545d69b4bd3d22ed10206010c8b23.js

There are other

2条回答
  •  醉话见心
    2021-02-01 09:05

    Facebook and Google both use a md5 suffix in their static resource file name.

    First, it's a general optimization for performance, we can versioning a static resource use the md5 of its file content (after minification) and set the cache-control = 10 years (nginx or apache). If you press forward/back button on your browser or view the page second time, the file will be retrieved from your local disk, not through the network (except you press the reload button, there will be a 304).

    Second, when you publish code online, you can first push all static resource, they will not conflict with old ones. And then you push all server-side code, all user will not have error access to your page.

提交回复
热议问题