Update the CSS of a Website without refreshing the Page

JavascriptJqueryHtmlCssAjax

Javascript Problem Overview


I've created a page with CSS. Now I must change from my editor to my browser and refresh the full page, just to have a look at every little change. But I don't want to refresh the page, because I have some animations.

So is there anything which I can use that my site updates automatically after a CSS update?
Maybe with JavaScript, jQuery, Ajax or something?

Javascript Solutions


Solution 1 - Javascript

Here you are: http://cssrefresh.frebsite.nl/

CSSrefresh is a small, unobstructive javascript file that monitors the CSS-files included in your webpage. As soon as you save a CSS-file, the changes are directly implemented, without having to refresh your browser.

Just insert the javascript file and it works!

But note: It only works when you have the files on a server!


Edit: LiveStyle

If you develop with Sublime Text and Google Chrome or Apple Safari, then you should use Emmet LiveStyle. This is a more powerful Live CSS-Reloader.
Now I use it instead of CSS Refresh.

If you want more information about this awesome plugin, please read the Post by Smashing Magazine

Solution 2 - Javascript

With jQuery you can create a function that reloads external stylesheets.

/**
 * Forces a reload of all stylesheets by appending a unique query string
 * to each stylesheet URL.
 */
function reloadStylesheets() {
    var queryString = '?reload=' + new Date().getTime();
    $('link[rel="stylesheet"]').each(function () {
        this.href = this.href.replace(/\?.*|$/, queryString);
    });
}

Solution 3 - Javascript

Have a look at http://livereload.com/.

It works as a browser plugin for OS X and windows. I like it because I do not have to embed additional javascript which I could accidentally commit in my versioning control.

Solution 4 - Javascript

I find browser plugins/extensions to be the easiest solution. They don't require any code changes to your individual sites. And they can be used for any site on the web — which is useful if I modify something in-memory real quick to hide a toolbar or fix a bug temporarily; once finished mucking with it, I can press a key and all the CSS is back to normal.

Once installed, (most) CSS reloaded plugins/extensions don't reload the CSS automatically. But usually work with something as simple as a toolbar button, a context menu item, and/or a simple key press to reload the CSS. I find this method is less error prone anyway, and is much less complicated then some of the automated solutions out there.

Some examples (feel free to suggest some others):

Chrome:

  • tin.cr (includes automatic reload, and can persist in-browser changes to source files)
  • CSS Refresh

Firefox:

Solution 5 - Javascript

Here is my little Project. Please give it a try
CSS Auto reload on Github

Solution 6 - Javascript

Yes you can manipulate the CSS via jQuery:

$(".classToBeReplaced").switchClass( "classToBeReplaced", "newClass", 1000 );

You could also use the toggleClass method.

http://api.jquery.com/toggleClass/

http://jqueryui.com/demos/switchClass/

Solution 7 - Javascript

Firebug for FireFox.

It's a plugin in an attached/separate window. Changes to HTML/CSS appear instantly, elements are highlighted.

Advantage over JS hacks is that you can't copy this accidentally to your production instance.

Solution 8 - Javascript

You are looking for Live Reload:

It's available as a browser extension and easy to implement

http://livereload.com/

Solution 9 - Javascript

The new open-source code editor, brackets, has a Live Development feature where you can edit CSS in the editor and it will immediately be reflected in the chrome browser. It currently only works for CSS editing, but HTML editing is coming soon!

Solution 10 - Javascript

Firebug for Firefox is my prefered method: https://addons.mozilla.org/de/firefox/addon/firebug/ You can edit HTML and CSS on the fly, quickly deactivate CSS rules (without deleting them), add or remove HTML and so on. If you wan't to tweak your design this is your choice. You can even save changes to a local copy, but I hardly ever use that feature.

Solution 11 - Javascript

This might help -> chaicode

Its a live CSS, Javascript and HTML editor that is opensource and a wip. github

Solution 12 - Javascript

If you are using Firefox then you can install Web Developer Toolbar 1.2.2 from Add-on of Firefox which has option of Reload Linked Stylesheets.

Solution 13 - Javascript

Try using CSS Brush, a chrome plugin for creating CSS live. You needn't have to write all CSS in a text editor, come back to browser and reload it, rather write the CSS live as if you were doing it in a text editor. You will have more features than a text editor here like context-sensitive-menu, use duplicate properties, select complete CSS path or a filtered path of a element directly from the page.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser1671245View Question on Stackoverflow
Solution 1 - JavascriptMichael SchmidtView Answer on Stackoverflow
Solution 2 - JavascriptSebass van BoxelView Answer on Stackoverflow
Solution 3 - JavascriptHendrikView Answer on Stackoverflow
Solution 4 - JavascriptJon AdamsView Answer on Stackoverflow
Solution 5 - JavascriptAlbert EinsteinView Answer on Stackoverflow
Solution 6 - JavascriptDarrenView Answer on Stackoverflow
Solution 7 - JavascriptLevente PánczélView Answer on Stackoverflow
Solution 8 - JavascriptBrian NoahView Answer on Stackoverflow
Solution 9 - JavascriptjeffslofishView Answer on Stackoverflow
Solution 10 - JavascriptZim84View Answer on Stackoverflow
Solution 11 - JavascriptzeusdeuxView Answer on Stackoverflow
Solution 12 - JavascriptKunalView Answer on Stackoverflow
Solution 13 - JavascriptramuView Answer on Stackoverflow