What Does The Question Mark at Then End of a CSS Include Url Do

What does the question mark at then end of a css include url do?

That loads all.css with a different query string so that if version 6637, for instance, is already cached on your machine, you'll get the new one (6638). Changing that number (in this case) will not give you a different file.

This is just a cache trick so they can send the file down with no expiration (i.e. you never have to ask for it again), because when it does change, the "file name", changes.


That said, you could make it so you load a different version based on the query string parameter. Doing so would be slightly non-trivial and akin to how you get different questions when you pass a different question ID to the URL of this page.

CSS: What does the question mark at the end of css do?

That's actually not part of CSS itself, but rather, part of the querystring to the image.

It's the same as:

http://foo/images/external.png?bar=baz

The site will take that querystring parameter and value as part of the request. It could make a decision on which file to serve, based on the value supplied.

Likely it's a version number. It helps get around the situations where your browser may have cached the image.

What is the meaning of ? (question mark) in a URL string?

Its name is query string. After the question mark you can pass key-value pairs and use them server-side.

What does the question mark at the end of filenames mean?

The ? in a URL denotes the start of the query string. A ? at the end with no variables following it is usually an unnecessary way of saying "this has absolutely no querystring".

It would be possible with a URL rewriting engine for example, to examine the incoming REQUEST_URI to see if it ends with ? and take a different action than requests not ending in ?, but that would be an unusual usage. It would much more common to just specify some value in the query string.

What is the question mark at the end of some script tag for?

Everything behind the question mark is a parameter that is delivered to the JavaScript.
In the given case a change in the version number prevents the browser from using the cached file and instead getting it from the server.

accessing the CSS in browser using question mark (?) in end

You need to add something after the ? then change it when you change the CSS. What is happening is a browser will cache anything that doesn't change for a specific period, it does that by checking file names. so main.css? is still main.css? Anything after the question mark is a query string, generally it's used to pass data to a particular file. In this case it's just used to change the file string so the browser will update it every time it changes without affecting the file itself.

There are a couple of ways you can handle this, the first is manually changing the version, probably the easiest idea if you have a single header file, as in a template system that always loads the same head data.

<link rel="stylesheet" type="text/css" href="assets/css/main.css?ver1/>

Then on next change:

<link rel="stylesheet" type="text/css" href="assets/css/main.css?ver2/>

If you'd rather do it automatically you can add a bit of PHP script to the css line like this:

 <link rel="stylesheet" type="text/css" href="assets/css/main.css?time=<?php echo filemtime('./assets/css/main.css');?>" />

This is essentially adding a value that changes every time you save the file and results in something like this, the next time I save the file that time= value will change:

<link rel="stylesheet" type="text/css" href="http://localhost/refficient/trunk/assets/css/main.css?time=1350305706" />

stylesheet linked with question mark and numeric value

It is for preventing the browser from caching the CSS. When a CSS is requested by some browsers, specifically Internet Explorer, the browser will have a local copy of the CSS.

When a request is given to a server as:

site.com/assets/css/screen.css?skdjhfk
site.com/assets/css/screen.css?5sd4f65
site.com/assets/css/screen.css?w4rtwgf
site.com/assets/css/screen.css?helloWd

The server at site.com sees only:

site.com/assets/css/screen.css

And gives the latest version. But when the HTML page is requesting the browser to fetch the CSS as: site.com/assets/css/screen.css, for the first time, it fetches from the site.com server. There are many possibilities that the content might be changed in the meantime when the next request is sent. So programmers generally add a ?and-some-random-text, which is called Query String. This will force the browser to get a new copy from the server.

Some more detailed explanation:

It is a well known problem that IE caches too much of html, even when
giving a Cache-Control: no-cache or Last-Modified header to
everypage.

This behaiviour is really troubling when working with querystrings to
get dynamic information, as IE considers it to be the same page
(i.e.: http://example.com/?id=10) and serves the cached version.

I've solved it adding either a random number or a timestring to the
querystring (as others have done) like this
http://example.com/?id=10&t=2009-08-06_13:12:56 that I just ignore
serverside.

Is there a better option? Is there another, cleaner way to acomplish
this? I'm aware that POST isn't cached, but it is semanticaly
correct to use GET here.

Reference: Random Querystring to avoid IE caching

Javascript src with question mark

David R's answer is pretty good, but I want to add a little bit info:

Usually there are two approaches for cache-breaking:

  1. Rename file;
  2. Add some hash to the end of the file.

The first approach may be better for some cases (see this question), but can be more painful. How would you keep this file in version control? What if there are many files like this?

The second approach is much easier. You just add something like app.js?_=<some_string>. The <some_string> can be whatever: timestamp, build number or just a random string.

For this approach, you may find it better to use automatic tools like gulp-rev.

Update: Honestly, it would be much better to have a revision number for all statics in the project: html, images, css, js.
There a lot of tools to make this automatic.

Alternatively, there are some technics, for example angular developers have the $templateCache service which allows the developer to put all the project's html (excluding index.html) in a single js file.

Remove question mark at the end of the URL

Use form method as post

<form action="sample.php"     method="post">
<input type="submit">
</form>


Related Topics



Leave a reply



Submit