Reputation: 227
I have a mediawiki 1.37 installation with a page using some css file. In this css file I have a background-image referring to a url, such as icon.gif
. The browser however issues the network requests to icon.gif?eff18
.
Questions:
?eff18
string?What I have checked so far:
icon.gif
without the additional query portion. So it looks like it is not some css preprocessing by the server.eff18
is the same for this gif file, for other files referenced by css, such as svgs or pngs, it is different.Background: I am familiar with the general idea of adding random query extensions to prevent loading things from cache. I am not familiar with the details of the css loader / minifier of mediawiki - but since the two browsers (Chrome & Fox) both show the background-url unmodified without that string in the css they receive from the server it should not be some fancy minification. In at least two experiments (one of the two chrome profiles and the fresh firefox profile) there is no fancy extension or whatever in place which might intercept the browser request. The thing happens in both browsers. So, who the hell is changing the URL - and how is this done? And, how can I turn this off or at least predict the value added, so I can add a decent preload link with the right extension? And, if I want to use that feature in my own frameworks, how would I activate it?
Upvotes: 4
Views: 218
Reputation: 48952
What component adds that string?
That string is a hash of the contents of the file, and is added by MediaWiki's ResourceLoader component. Specifically, ResourceLoader.php on the backend and mediawiki.loader.js on the frontend.
How can I determine this string myself?
ResourceLoader is using the FNV 1 32-bit hash function, so you could always compute the same function (the two source files above each contain an implementation, one in PHP and one in Javascript).
The normal way to handle something like this is to to use a CSS preprocessor. That way you can refer to the unversioned name in your source CSS file, and then have the processor substitute the correct versioned name automatically. I'm not sure the best way to do this with MediaWiki specifically.
How can I turn off this adding of the string, since I need to issue a preload for this file?
ResourceLoader has configuration options, but I don't see a straightforward way to turn this off. Given the complexity of the ResourceLoader architecture, and the fact that it was designed to improve overall performance, it seems unlikely to be worth the effort to try and disable this feature.
Upvotes: 1
Reputation: 26
Media wiki use Less.php https://github.com/wikimedia/less.php parser to convert .less file to css file, and that random query string is generated automatically by this library located in ./vendor/wikimedia/less.php you need to hack this library to get what you want but seems too complicated,
If you ask which modules started to parsing that .less file template then you could look at file /resourceloader/ResourceLoader.php, begin at method in line 1862 :
public function getLessCompiler( array $vars = [], array $importDirs = [] ) {
global $IP;
...
However my answer is not complete i hope this will help you ...
Upvotes: 0