Weird characters at the end of src/href attributes in head tag

不打扰是莪最后的温柔 提交于 2019-12-11 00:35:54

问题


Quick question : Why is drupal adding characters at the end of the src or href attributes in the link and script tags in the head of the page ? I have this :

<link type="text/css" rel="stylesheet" media="all" href="/ste_thecle/modules/views/css/views.css?n" />

And it is the same for every stylesheet and script loaded. I can't figure out why it's doing that, and I think maybe it's the reason why my theme is all messed up in IE...

Thanks.


回答1:


Each time the browser loads an external JavaScript file, the browser put the file in its cache. This way, the second time you will reload the page and try to load the same external file, the browser will use it from the cache.

If you make a change in the JavaScript file and try to reload your page, the changes will not take effect because the browser will use the cache file.

To prevent this behavior, Drupal will add a random value at the end of the URL of the JavaScript file. This way the browser will see the file as a new file and will not use the file in the browser cache.

A good practice is to remove this functionality in production stage so the page will load faster.




回答2:


These things are added in order to force the cache control. It has nothing to do with the messed up theme in IE.




回答3:


Because a different query string (?n) is added every time, your browser 'thinks' that the resource is different, so it reloads the file instead of retrieving it from cache. By doing this, Drupal makes sure that you're not looking at stale files that have been changed since they were cached.



来源:https://stackoverflow.com/questions/3625419/weird-characters-at-the-end-of-src-href-attributes-in-head-tag

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!