css file not getting updated - css

the font of the content of my facebook app keeps getting italicized even when i've removed the italics from the css file. if i make minor changes in the css file and upload it to the server, the firebug shows the unedited previous css file and hence, the app keeps showing unformatted content. what exactly is going wrong here?
i made a new css file and copied the contents of the previous css exactly as it was, and i linked it in all the files which require css. but when i upload these files to the server, facebook canvas doesn't show any css at all. i replaced the css filename with the previous one, and it works. why is this?

Actually it looks like facebook is currently experiencing some weird problems with styling. It doesn't cache any new styles, only displays what was previously cached (from yesterday). If you provide a new stylesheet url it will not be able to pull it up (like that url doesn't exist).
During normal conditions what others already suggested should work.

Facebook does like to cache things. Persistently. I don't know why the new file wouldn't have worked, by I can recommend 'spoofing' your css filename with a spurious querystring variable, and incrementing it each time you make an update.
eg
href="my_css_file.css?x=1"

Sounds like the browser is caching your CSS file, which is why even Firebug sees the older version.
There are numerous ways you can prevent the browser from caching your CSS file during development (once in production mode, you probably want it to remain in the cache). The most common technique used by web frameworks like Ruby on Rails is to append a random query string to the URL, like so:
<link rel="stylesheet" type="text/css" href="style.css?96234987" />
...but the trick is that it should be different every time, so the browser thinks it's a different file.
Here are links to a simple trick for PHP, a JSP example, and other possible methods.

According to Include files on facebook developer wiki:
Stylesheet includes are cached automatically by Facebook. Just include a tag like:
<link rel="stylesheet" type="text/css" media="screen"
href="http://yourapp.com/stylesheets/style.css?v=1.0" />
Increment the version number upon each change to your style sheet, as specified above.

Related

codeigniter website on a host- CSS changes does not change front end elements

My site is in a Host. (Not localhost)
Framework: CodeIgniter.
Changes made using CSS: Flot chart's legend
I did changes to front end using Chrome tools/developer tools.
I can see all the changes I made instantly.
I FTP to the site, downloaded the CSS file, did necessary changes (same as chrome developer changers) and uploaded the CCS file.
I access the site, but I cannot see the changes I made using CSS file.
Check if your hosted CSS contains the latest changes
If CSS is ok try to open chrome dev tools and inspect the element that you are trying to modify. Scroll through the CSS applied to that element and check if your styles are there.
If you didn't find any of the styles that you are tring to apply to the element probably you misspelled the selector name. Remember to check .class #id
also, in order to ensure that your CSS files are not cached suffix your php files like this
<link href="/stylesheet.css?<?php echo time(); ?>" rel="stylesheet" type="text/css" /&glt;
EDIT
tip above also works for any resource! (css, javascript files, images ...)
Try Ctrl+F5. It's hard refresh
change the name of the css file so there are no cache issues and then check. if that does not work then look at your source code and copy paste the address of the css file to make absolutely certain you have the link correct.
I think your CSS is still cached so have a Look at this popular question: How to force browser to reload cached CSS/JS files?
There are some solutions how you can force your browser to refresh the CSS or js.
The easiest answer you will get is using something like this:
/styles/screen.css?v=1234
If you did a change all you have to do is to +1 the counter!
In PHP you van also use this:
<link rel="stylesheet" href="mycss.css?v=<?php echo filemtime('mycss.css') ?>"/>
It's like an autocounter using the timestamp of the CSS file.
In the DevTools Settings (F1) or in the Network panel (depends on what version of Chrome you are using) tick the Disable cache (while DevTools is open) checkbox. If caching is your problem, it should get fixed.

Is it necessary to append querystrings to images in an img tag and images in css to refresh cached items?

I know that a common practice is to set an expire time far in the future for css, javascript and image files and then make sure that all browsers fetches the latest content as soon the files changes by appending a querystring (or changing filename) like this
From this <link rel="stylesheet" type="text/css" href="base.css">:
to this:
<link rel="stylesheet" type="text/css" href="base.css?v=1234">
or:
<link rel="stylesheet" type="text/css" href="base_1234.css">
But what about images referenced in a css file?
// Inside base.css
background: url(/img/logo.png)
// Is this necessary(?):
background: url(/img/logo.png?v=1234)
Or will /img/logo.png be reloaded when base.css changes filename to base.css?v=1234 or base_1234.css automatically?
And also, what about images in src for img-tags?
The browser is making these requests after determining an absolute path, so if you are 'cache busting' your static assets in this way, you do need to do it for each file individually, no matter where it's called. You can, however, make it easer on yourself by making it a variable on the backend.
You can append the string as a variable that you only have to update in one place on your backend, probably in conjunction with a CSS pre-processor like LESS or SASS to get all your images.
Or use relative paths to your advantage by adding the version to the base url (site.com/folder/styles.css => site.com/v123/folder/styles.css). This can be added to an existing static asset base url variable in your app, then on the server you can just use a UrlRewrite to strip out the version. This way all the images relatively referred to from your CSS automatically get the version too, having the same 'cache busting' effect.
You could be extra clever and set the variable automatically as part of your build process as the last commit hash from you version control system - which will also make future debugging easier.
From my experience the cache busting of the css is not recursive. So the querystring at the end of the image referenced in css is required to bust the cache.
To be sure all images are fresh you may want to also cache bust with the querystring version (img.png?v=1234).
Chrome seems to be the worse of the browser-bunch for not updating it's cache (perhaps due to the new predictive caching methods it's using) and the way to do this is indeed with a querystring.
This website takes it one step further and uses the simple JavaScript Date().getTime(); method (with or without jQuery) that is attached to all img tags.
Another solution is to write a javascript code so that the browser does not pick up image
from the cache and loads it everytime.
The benefit of the above is that individual image-file renaming, for the sake of the querystring, is not needed as the JavaScript handles this in one pass.
While it does use a single line of JavaScript to accomplish this, it's not as high-maintenance as tracking down every img element in a large CSS file, which can take time and add to the file size.

How to Prevent Browsers from Caching CSS Files?

When I make a page, link it to a CSS file, and open it in a browser, it works fine.
But if a make a change and refresh the page again between very short time periods, the change is not reflected. But after sometime, when i refresh the page again, the changes appear.
So, somehow the browser keeps the CSS file cached and expires it after sometime. How to make the browser cache no CSS or HTML file.
It would be better if i can block it on a particular domain.
I'm on Ubuntu, using Chrome and Firefox, trying to prevent browsers from caching CSS files on 'localhost'... How to do it...
Thanks...
Something as simple as this should work:
<link rel="stylesheet" src="/css/screen.css?v={CURRENT_TIMESTAMP}">
Just replace {CURRENT_TIMESTAMP} with the actual timestamp in your server side code. This makes the browser think it's a new file because of the query string and it will be downloaded again. You could also use the actual modification time of the file (filemtime('/path/to/css/screen.css') if you're using PHP) which should prevent unnecessary downloads.
You can open Developer Tools by pressing Ctrl+Shift+J and then you'll find a cog icon in bottom right. When you click on it you should see an option to disable caching.
It would help to know how the website is hosted, as you can configure this in most web servers.
Also, it's a good idea to introduce a cache busting mechanism which would modify the links to the CSS files in question when you change the CSS files' contents. Browsers would then reload the CSS file because the HTML refers to a different URL.
A good example of a cache busting mechanism is the ruby on rails 3.1 asset pipeline which also minifies files and gzips them if the browser supports them:
Rails 3 - Asset Pipeline -- What does it mean to me?
http://2beards.net/2011/11/the-rails-3-asset-pipeline-in-about-5-minutes/
The seemingly-inelegant but rock solid approach is to give the asset a new name, when the content changes. This solves the problem for all your users, not just you:
<link rel="stylesheet" src="/css/screen_034.css">
<link rel="stylesheet" src="/css/screen_035.css">
<link rel="stylesheet" src="/css/screen_036.css">
Or maybe (but it's more of a pain to change in an IDE, and sometimes causes unrelated problems with caching):
<link rel="stylesheet" src="/css/screen.css?pretend_version_number=034">
Nothing else works quite as well in large scale production environments, where millions of copies of an older css file may be sitting in various intermediate or browser caches. Some clients ignore cache control headers, and you don't really want caching subverted anyway, at least not in production.
In development you can press Ctrl+Shift+J (Chrome) and turn off caching.

Printing time behind your .css files, why?

In some sourcecodes i see this:
<link rel="stylesheet" href="/css/style.css?201007071609" type="text/css" />
Now is my question: why do people print 201007071609 behind style.css?
This forces the browser to not load the css from cache and rather take the latest version from the server
see related article
Another trick developers do is to add a random string or a timestamp to force refresh the css page.
That's a way to make sure that clients don't cache older versions of the same file. If the URL is different, the client will retrieve the file from the server instead of from cache. So, for example, if a new version of the site was published, that would be a way to make sure visitors see the right CSS.
This forces the browser to retrieve a fresh copy of the file, rather than loading a cached version. This is important when your html has changed and requires an up to date css file to prevent it from displaying incorrectly.

How do tools like the web dev toolbar get the entire css file of a site?

The web dev toolbar for Firefox is quite an impressive tool.
What I am completely clueless about is how does this tool get the css stylesheet file of a site? This is hosted on a host which is secure etc. I am completely stumped.
I must be thinking about this in all the wrong way.
Thanks
The client (in this case Firefox) has to download the CSS file in order to render the page correctly. The plugin (in this case Firebug) simply requests the proper URL and the browser it gets it--most likely from the cache. There is no real mystery here.
In every HTML file, there's a link to the CSS stylesheet, or else the browser wouldn't know where to find it, thus losing the ability to render the page correctly.
It's in the form of <link rel="stylesheet" type="text/css" href="theme.css">,
I'd like to add that regardless of whether the host is 'secure' or not, it still is presenting the file to the client.
Unless, of course, you're looking at a XML file. Then you need to consult the XSL which'll tell you where the stylesheet is.

Resources