Weird characters at the end of src/href attributes

2019-07-18 05:02发布

问题:

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.