Accessing The CSS in Browser Using Question Mark () in End

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" />

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.

How to remove trailing question mark from a GET form with no fields?

In my case I'm using window.location, not sure it's the best alternative, but it's the only one I could make it work:

$('#myform').submit(function()
{
... if all parameters are empty

window.location = this.action;
return false;
});

My real use was to convert GET parameter to real url paths, so here is the full code:

$('#myform').submit(function()
{
var form = $(this),
paths = [];

// get paths
form.find('select').each(function()
{
var self = $(this),
value = self.val();

if (value)
paths[paths.length] = value;

// always disable to prevent edge cases
self.prop('disabled', true);
});

if (paths.length)
this.action += paths.join('/')+'/';

window.location = this.action;
return false;
});

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.

Why does a diamond with a questionmark in it � appear in my HTML?

This specific character � is usually the sign of an invalid (non-UTF-8) character showing up in an output (like a page) that has been declared to be UTF-8. It happens often when

  • a database connection is not UTF-8 encoded (even if the tables are)

  • a HTML or script source file is stored in the wrong encoding (e.g. Windows-1252 instead of UTF-8) - make sure it's saved as a UTF-8 file. The setting is often in the "Save as..." dialog.

  • an online source (like a widget or a RSS feed) is fetched that isn't serving UTF-8

CSS file not refreshing in browser

Try opening the style sheet itself (by entering its address into the browser's address bar) and pressing F5. If it still doesn't refresh, your problem lies elsewhere.

If you update a style sheet and want to make sure it gets refreshed in every visitor's cache, a very popular method to do that is to add a version number as a GET parameter. That way, the style sheet gets refreshed when necessary, but not more often than that.

<link rel="stylesheet" type="text/css" href="styles.css?version=51">

Question mark characters display within text. Why is this?

The following articles will be useful:

10.3 Specifying Character Sets and Collations

10.4 Connection Character Sets and Collations

After you connect to the database, issue the following command:

SET NAMES 'utf8';

Ensure that your web page also uses the UTF-8 encoding:

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

PHP also offers several functions that will be useful for conversions:

  • iconv
  • mb_convert_encoding


Related Topics



Leave a reply



Submit