Skip to main content
Topic: Remove query strings from static resources (Read 3768 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Remove query strings from static resources

I wish to know the effects of removing the query strings from ElkArte combined files for js and css as they are considered as static resources. I am testing it by commenting out this part ". $this->_archive_stale;" in the site combiner file.

And I wish to know how do I remove the query string from "fontawesome-webfont.woff2?v=4.4.0" and its effects if I do so.

Re: Remove query strings from static resources

Reply #1

The query is there to "force" refreshing on updates/upgrades.
What would be the advantage of removing it?
Bugs creator.
Features destroyer.
Template killer.

Re: Remove query strings from static resources

Reply #2

Actually, web tests always raise this issue and while I was seaching around, I found this: https://stackoverflow.com/a/23604412. But I don't understand it as much as programmers do, so I asked in here.

Re: Remove query strings from static resources

Reply #3

In reading that a bit, the issue of "Using query strings prevents proxy caching" seemed to be somewhat specific to the Squid-Cache, but that was also addressed back in 2008, or at least a setting was added so that it would work as expected.

I'm going to assume you have your web server set up to set expire headers on your asset files (css js images etc) that are far in the future, how far is up to you.  Those directives are done in your web server configs.   With those headers being sent, if you edit or add to your sites js/css files without the ?v=x.y.z your users may not see see the change,  Of course even with them set a ctrl+f5 is often needed.

QuoteAnd I wish to know how do I remove the query string from "fontawesome-webfont.woff2?v=4.4.0" and its effects if I do so.
Those are in the font-awesome.min.css file   You would have to edit that file.  The downside is that without that, a cache may supply an older or newer version of that asset which may not be compatible with the rest of the css.



Re: Remove query strings from static resources

Reply #4

i ignore those warnings. too much hassle with minor benefit.

Re: Remove query strings from static resources

Reply #5

Ignoring is a good choice actually. But I like learning and doing it the other way too. This is my hobby, so nothing serious.


Re: Remove query strings from static resources

Reply #6

And considering how the cache of Chrome is persistent and "difficult" to cleanup, change the URL is actually the only reliable way to be sure the content is changed when it really needs to be...
Bugs creator.
Features destroyer.
Template killer.

Re: Remove query strings from static resources

Reply #7

Out of curiosity, which tools warn specifically? Using ?v=1.2.3 is quite common for good reason.[1] You could also use something like /scriptname/1.2.3/script.js or /scriptname-v1.2.3.js instead but that might be slightly harder to implement on the server-side.
And I'm not sure if it's terribly relevant that some older proxies may not cache it. The browsers still should based on the expire headers.

Re: Remove query strings from static resources

Reply #8

You can check using https://tools.pingdom.com and https://gtmetrix.com with a little to worry about it, as at least according to https://gtmetrix.com, its priority is low.

I however found that your suggestions are interesting since our css or js are in this kind of format: hive-xxxxxx.css/js?v.1.2.3. Can't we not implement without many hassle (via addon mainly), only using this hive-xxxxxx.css/js, and rewrite it in our server side, may be like this for nginx:
Code: [Select]
location ~* \.(css|js) {
rewrite "/(.+)\.[\d]{10}\.(css|js)$" /$1.$2 last;
}
and may be like this for apache2 htaccess
Code: [Select]
RewriteEngine on
RewriteRule ^(.*)\.[\d]{10}\.(css|js)$ $1.$2 [L]
I only think this is possible if I assume correctly that the xxxxxx in hive-xxxxxx.css/js is changed every time its sources change which might not be.  ;D

If it is possible, can it be extended to woff2 file for font-awesome too?

And if possible, I'd actually prefer if all these static contents are served via cdn which is gmetrix considered as medium priority.  :D

Re: Remove query strings from static resources

Reply #9

Pingdom says "more at Google Developers" but it doesn't look like Google mentions it at all?

At GTmetrix I don't seem to get a warning about such query strings.

QuoteI only think this is possible if I assume correctly that the xxxxxx in hive-xxxxxx.css/js is changed every time its sources change which might not be.  ;D
The sha1 hash seems to be based on the filenames (see here) and just about the only filenames that change occasionally are jquery-3.1.1.min.js. However, there's no reason for the
unique stale" right below to be appended as a query string. It should be no trouble at all to change the '?' to a '-'.

The woff doesn't need one either because it already includes a changing version number:
Code: [Select]
http://netdna.bootstrapcdn.com/font-awesome/4.2.0/fonts/fontawesome-webfont.woff?v=4.2.0
That could be easily removed here but it'd be at a big danger of being forgotten while updating the CSS file (which comes that way straight from the horse's mouth).

Edit: but you could probably write some kind of Travis test to prevent regressions there. Still, it'd take a whole lot more trouble than just a simple deletion. ;)

Re: Remove query strings from static resources

Reply #10

Quote from: emanuele – And considering how the cache of Chrome is persistent and "difficult" to cleanup, change the URL is actually the only reliable way to be sure the content is changed when it really needs to be...
Well then I guess Elk's built in minifier could add the Unix timestamp of the most recently modified file.
LiveGallery - Simple gallery addon for ElkArte

Re: Remove query strings from static resources

Reply #11

Quote from: live627 –
Quote from: emanuele – And considering how the cache of Chrome is persistent and "difficult" to cleanup, change the URL is actually the only reliable way to be sure the content is changed when it really needs to be...
Well then I guess Elk's built in minifier could add the Unix timestamp of the most recently modified file.
I second this. I think I can may a simple addon to do that for personal test. Let me see...

Re: Remove query strings from static resources

Reply #12

And a cron job can be set up to purge old files with glob() om nom nom.
LiveGallery - Simple gallery addon for ElkArte

Re: Remove query strings from static resources

Reply #13

The query string (?xyz123) is currently built from the included files modified timestamp.  We could move that to the actual filename but I'm not sure what we are trying to fix anymore  O:-)

Re: Remove query strings from static resources

Reply #14

Yup, that's the idea. ;)