accessing the CSS in browser using question mark (?) in end

前端 未结 2 1880
眼角桃花
眼角桃花 2021-01-22 05:23

can someone explain what is the difference in accessing CSS in browser by putting question mark ? in the end and why the new CSS is not making any affe

2条回答
  •  时光说笑
    2021-01-22 06:16

    You need to add something after the ? then change it when you change the CSS. What is happening is a browser will cache anything that doesn't change for a specific period, it does that by checking file names. so main.css? is still main.css? Anything after the question mark is a query string, generally it's used to pass data to a particular file. In this case it's just used to change the file string so the browser will update it every time it changes without affecting the file itself.

    There are a couple of ways you can handle this, the first is manually changing the version, probably the easiest idea if you have a single header file, as in a template system that always loads the same head data.

    
    

    This is essentially adding a value that changes every time you save the file and results in something like this, the next time I save the file that time= value will change:

    
    

提交回复
热议问题