1

I just came across a website pagesource and saw this in the header:

<link href="../css/style.css?V1" rel="stylesheet" type="text/css" />

Could we actually pass GET data to css? I tried searching but found no results apart from using PHP. Could anyone help make meaning of the ?V1 after the .css

I know this forum is for asking programming problems, however I decided to ask this since I have found no results in my searches

D. Rattansingh
  • 1,569
  • 3
  • 19
  • 30

3 Answers3

1

First of all, no you can't pass GET parameters to CSS. Sorry. That would have been great though.

As for the example url. It can either be a CSS page generated by any web server (doesn't have to be PHP). In this case the server can serve different pages or versions of the same page which might explain the meaning of V1, Version 1. The server can also dynamically generate the page with a server-side template. This is an example from the Jade documentaion:

http://cssdeck.com/labs/learning-the-jade-templating-engine-syntax

It can also just be used as cache buster, for versioning purposes. Whenever you enter a url the browser will try to fetch it only if it doesn't already have a cached copy which is specific to that URL. If you have made a change in your content (in this instance the css file) and you want the browser to use it and not the cached version you can change the url and trick the browser to think it's a new resource that is not cached, so it'll fetch the new content from the server. V1 can then have a symantic meaning to the developer serving as a note (ie I've changed this file once...twice..etc) but not actually do anything but break the cache. This question addresses cache busting.

Community
  • 1
  • 1
Lior
  • 1,599
  • 17
  • 21
1

There are different concepts.

At first, it only is a link - it has a name, it might have an extension, but this is just a convention for humans, and nothing more than a resource identifier for the server. Once the browser requests it, it becomes a server request for a resource. The server then decides how to handle this request. It might be a simple file it just has to return, it might be a server side script, which has to be executed by a server side scripting interpreter, or basically anything else you can imagine.

Again, do not trick yourself in thinking "this is a CSS file", just because it has a css extension, or is called style.

Whatever runs at the server, and actually answers the request, will return something. And this something then is given a meaning. It might be CSS, it might be HTML, it might be JavaScript, or an image or just a binary download. To help the browser to understand what it is, the server returns a Content-Type header.

If no content type is given, the browser has to guess what it is. Or the nice web author gave a hint on what to expect as response - in this case he gave the hint of text/css. Again, this is how the returned content should be interpreted by the client/browser, not how that content is supposed to created on the server side.

And about the ?V1? This could mean different things. Maybe the user can configure a style (theme) for the website and this method is used to dispatch different styles. Or it can be used for something called "cache busting" (look it up).

Shi
  • 4,178
  • 1
  • 26
  • 31
  • I already researched cache busting, makes sense. However something you mentioned that peaked my interest is configuring for themes, since it's something I never did. I will look it up, thanks – D. Rattansingh Jun 15 '14 at 08:37
0

You can pass whatever you want; the server decides what to do with the data.

After all, PHP isn't your only option for creating a server. If i wrote a server in Node.js, set up a route for /css/style.css and made it return different things depending on what query was given, neither the server nor browser will bat an eyelid.

Scimonster
  • 32,893
  • 9
  • 77
  • 89
  • I still do not understand what the ?V1 could possibly mean. Is this linking to a css file? javascript file? – D. Rattansingh Jun 15 '14 at 08:17
  • 1
    @D.Rattansingh That's typically used for cache-busting. Change it to ?V2 and your browser will request a new copy of the file rather than using what it has cached locally. – Tieson T. Jun 15 '14 at 08:23
  • 1
    Chrome's developer tools (F12) settings has an invaluable checkbox called `Disable cache (while DevTools is open)` – ChaseMoskal Jun 15 '14 at 09:40