Refresh CSS Bookmarklet that works on latest Chrome? - css

Im developing a site and I would like the page to refresh when a change is detected to a CSS file. I used to be able to do this easily with the following bookmarks, but now none of them work on Chrome.
http://david.dojotoolkit.org/recss.html
http://calvincorreli.com/2006/02/13/re-recss/
http://www.paulirish.com/2008/how-to-iterate-quickly-when-debugging-css/
I cant change the HTML of the site im working on so I cant use the livereload app. Ideally I would keep using Chrome but I would switch to another browser if necessary.

You have two ways:
Edit css file and use livereload to reload it automatically in Chrome
Change your CSS in Chrome and save it (without IDE using).
About livereload(it works not for css only).
Use livereload. You need download Livereload 2 and add javascript file to your page or use Chrome extension.
This script is meant to be included into the web pages you want to monitor, like this:
<script src="http://localhost:35729/livereload.js"></script>
LiveReload 2 server listens on port 35729 and serves livereload.js over HTTP (besides speaking the web socket protocol on the same port).
A slightly smarter way is to use the host name of the current page, assuming that it is being served from the same computer. This approach enables LiveReload when viewing the web page from other devices on the network:
<script>document.write('<script src="http://'
+ location.host.split(':')[0]
+ ':35729/livereload.js"></'
+ 'script>')</script>
However, location.host is empty for file: URLs, so we need to account for that:
<script>document.write('<script src="http://'
+ (location.host || 'localhost').split(':')[0]
+ ':35729/livereload.js"></'
+ 'script>')</script>
LiveReload.js finds a script tag that includes .../livereload.js and uses it to determine the hostname/port to connect to. It also understands some options from the query string: host, port, snipver, mindelay and maxdelay.
From GitHub
About changing CSS in Chrome devtools.
Just take a minuit and watch a demo from Paul Irish

Maybe it can fit your needs, since I don't know what editor you use there is two nice ones with embed live editing, are: Brackets IO (free) and JetBrains WebStorm. If you dont ever want to change editors, like Pinal said, Livereload it's a good one, but sometimes its litte bug to make it, but it's a good choice!

You can use Code Kit https://incident57.com/codekit/ and get the free trial and use it for 10 days or you can buy it for $29, I think its totally worth it. You can use Fire.app also http://fireapp.kkbox.com/. Tincr is also a nice app you can use and I think this one is free http://tin.cr/. Hope this helps!

Do you see any errors in chrome console? all 3 bookmarklets work fine for me on chrome 35.0.1916.153.
The change might come from your sites server, e.g some servers block requests with additional parameters. In that case you'll need to modify bookmarklet to not add it.

Related

Preview site without cache?

I have a Wordpress site on a self-hosted domain. There is no cache plugins. I am using Firefox.
When I make changes to the CSS it can sometimes take hours for anything to change in the browser.
I use Plesk and its the same in the Plesk preview so the trick with a random hash and query doesn't work either.
How to solve this please? I need to see live changes please.
try use Ctrl + F5 to hard refresh your browser
You can do is press ctrl + f5 or ctrl + shift + r. You can also use "Work Offline" mode if your using Firefox.
The way I get around this is to add a version to the css file that's the time it has been changed last:
<link rel="stylesheet" href="path/style.css?v=<?php echo filemtime("path/style.css"); ?>" type="text/css" />
EDIT: Alternatively you could use a plugin that ultimately does the same thing: https://wordpress.org/plugins/stylecss-load-last-version/
Note: these are solutions that will always load the most recent css file for all. If you only want to test, use the solution of #user3085741 (refresh the page).
Another alternative when you are doing development would be to turn off caching in Firefox altogether:
"Hamburger menu"->Preferences->Advanced->Network. Check the box that says "Override cache management" and limit the cache to 0 MB.
This way no pages will be cached in Firefox until you decide to turn caching back on (just uncheck the override box you checked above).
This won't help if something else is doing the caching, like a proxy or the server itself.
Hope this is helpful.

Is it possible to load a local css file to the browser for certain domains?

Using developer tools, I can amend a css file for a site I'm currently viewing in a browser.
I want to, effectively, do the same - but instead of amending the css file, loading a local css file, just for that particular domain.
Another way of phrasing it: "When any page of stackoverflow.com is loaded, load C:\test.css to the browser".
Yes, it's possible. Have a look at http://userstyles.org.
Userstyles.org offers CSS files for usage with the extension "Stylish", and Stylish recently announced that they are becoming evil (https://forum.userstyles.org/discussion/comment/109966/#Comment_109966) and can therefore not be used anymore.
One can use the styles with greasemonkey, but then the activation for various websites doesn't work anymore (the CSS is converted into a JS file and the list of sites where it should be applied onto is hardcoded inside an if-statement in that script). I.e. in order to use e.g. "dokuwiki highlight and full width" on a site using dokuwiki but not being http://dokuwiki.org, you have to edit that if-statement and reload.

CSS file not refreshing in browser

When I make any changes to my CSS file, the changes are not reflected in the browser. How can I fix this?
The fix is called "hard refresh"
http://en.wikipedia.org/wiki/Wikipedia:Bypass_your_cache
In most Windows and Linux browsers: Hold down Ctrl and press F5.
In Apple Safari:
Hold down ⇧ Shift and click the Reload toolbar button.
In Chrome and Firefox for Mac:
Hold down both ⌘ Cmd+⇧ Shift and press R.
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">
A good way to force your CSS to reload is to:
<link href='styles.css?version=1' rel='stylesheet'></link>
And then just increment the version number as you change your CSS. The browser will then obey. I believe Stack Overflow uses this technique.
I always use Ctrl+Shift+F5 out of habit, it should force a full-refresh including by-passing any http proxies you may be going through.
I had this issue. Turns out I completely forgot I had CloudFlare setup on the domain I was live testing on.
CloudFlare caches your JavaScript and CSS. Turned on development mode and BAM!
Do Shift+F5 in Windows. The cache really frustrates in this kind of stuff
This sounds like your browser is caching your css. If you are using Firefox, try loading your page using Shift-Reload.
Having this problem before I found out my own lazy solution (based on other people suggestions). It should be helpful if your <head> contents go through php interpreter.
To force downloading file every time you make changes to it, you could add file byte size of this file after question mark sign at the end.
<link rel="stylesheet" type="text/css" href="styles.css?<?=filesize('styles.css');?>">
EDIT: As suggested in comments, filemtime() is actually a better solution as long as your files have properly updated modify time (I, myself, have experienced such issues in the past, while working with remote files):
<link rel="stylesheet" type="text/css" href="styles.css?<?=filemtime('styles.css');?>">
The Ctrl + F5 solusion didn't work for me in Chrome.
But I found How to Clear Chrome Cache for Specific Website Only (3 Steps):
As the page is loaded, open Chrome Developer Tools (Right-Click > Inspect) or (Menu > More Tools > Developer Tools)
Next, go to the Refresh button in Chrome browser, and Right-Click the Refresh button.
Select "Empty Cache and Hard Refresh".
Since I found this thread having the same problem, 10 YEARS later, I'll add my own solution too. I use PHP most of the time, and rather than requiring the user to press unusual buttons to refresh the page, or myself to remember to bump a version number embedded in a link, I used the filemtime() function to get the modification time of the css file (as a unix timestamp), and then use THAT number as the parameter.
$FILE_TIME = filemtime("main.css");
$CSS_LINK = "main.css?version=$FILE_TIME";
While results in a URL like:
http://example.com/blah/main.css?version=1602937140
This entirely disables caching, since every time the page is refreshed, it will believe it needs to grab the CSS file again, changed or not... but that's far less frustrating than forgetting to manually update this trick and wasting time wondering why it isn't right. You can always remove it from a production server.
If you are using plain HTML, you could probably engineer a javascript wrapper or some such, but that's probably more trouble than it's worth.
Have you tried renaming the new version of your CSS to CSSv2.css and then directing your page to use that? If that solves the stale-file issue, then you're just experiencing non-refreshing files. If not, you've got bigger issues.
If you're using ASP.NET web forms, make sure that you are using the right theme:
I just spent about an hour trying to solve this!
Is this a local custom CSS file? Is this your website? Maybe you should clear your cache.
Also the last CSS declaration takes precedence.
I faced the same problem. Renaming the file worked for me.
The reason this occurs is because the file is stored in the "cache" of the browser – so there is no need for the browser to request the sheet again. This occurs for most files that your HTML links to – whether they're CDNs or on your server, for example, a stylesheet. A hard refresh will reload the page and send new GET requests to the server (and to external b if needed).
You can also empty the caches in most browsers with the following keyboard shortcuts.
Safari: Cmd+Alt+e
Chrome and Edge: Shift+Cmd+Delete (Mac) and Ctrl+Shift+Del (Windows)

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.

Changing favicon based on theme

Is there a built in way to change the favicon for different themes? If not would it be as simple as creatign a custom control to emit the link tag with the correct url to the icon?
Update
So based on what I have found in order to do this, it looks like I am going to have to create an http handler that will intercept all calls for favicon.ico.
This handler will then determine which theme we are using (in my case it will be based on the domain name), it will then output the themed favicon.ico from the various themes folders.
Since I am supporting IE7, I'm thinking this is the only option I have. Still curious if anyone else has a better way.
As long as your user is not using IE, that should be fine. IE (up to at least version 7) only reads the favicon.ico file and completely ignores the link tag.
After some research and thought It looks like the only way to do this and still support IE7 and earlier (I am not sure if IE8 updated support for favicon or not). Would be to dynamically serve the icon to do this you can do the following:
Create and register an HttpHandler to process requests for FavIcon.ico
Configure IIS to send requests for .ico files to ASP.Net (If your using IIS6 or earlier)
Run the logic that you use to determine which theme and from that find the .ico your going to serve up, and send it to the browser.
Note that per W3Schools
http://www.w3schools.com/browsers/browsers_stats.asp
You should expect about 1/2 your users to be using IE.

Resources