Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an easy way to reload css without reloading the page?

I'm trying to make a live, in-page css editor with a preview function that would reload the stylesheet and apply it without needing to reload the page. What would be the best way to go about this?

like image 706
Stephen Belanger Avatar asked Jan 07 '10 23:01

Stephen Belanger


People also ask

How do I force a reload CSS?

General solutionPressing Ctrl + F5 (or Ctrl + Shift + R ) to force a cache reload.

How do I change the content of a page without reloading it?

AJAX allows web pages to be updated asynchronously by exchanging small amounts of data with the server behind the scenes. This means that it is possible to update parts of a web page, without reloading the whole page. Classic web pages, (which do not use AJAX) must reload the entire page if the content should change.

What happens to CSS when we load up a webpage?

The CSS file will be downloaded when the HTML file is parsing. The DOM(document object model) will be created by browser. DOM means the reference of the all the elements in the in HTML file.

How do you load CSS on pages?

CSS can be added to HTML documents in 3 ways: Inline - by using the style attribute inside HTML elements. Internal - by using a <style> element in the <head> section.


1 Answers

Possibly not applicable for your situation, but here's the jQuery function I use for reloading 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);     }); } 
like image 107
harto Avatar answered Oct 06 '22 01:10

harto