forked from livereload/livereload-js
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use readyState to trigger removal of old <link> [#198]
Previously we had a fixed 200ms delay before removing the old stylesheet on live CSS refresh. I'm not sure why it has been done that way. Problem is that Sprockets asset pipeline often takes more time to produce a CSS file, causing a flash of unstyled content for Rails developers. Waiting until readyState is 'complete' is clearly a superior way to detect when the new stylesheet has finished loading, and that's what this commit implements. Tested in Safari, Chrome, Firefox and Opera, and seems that it should work in IE too.
- Loading branch information
Showing
4 changed files
with
33 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
body { | ||
background: green; | ||
background: red; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>LiveReload Test</title> | ||
<link rel="stylesheet" href="http://localhost/~andreyvit/testcss.php"> | ||
</head> | ||
<body> | ||
<script src="../../../dist/livereload.js?host=localhost" async defer></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<? | ||
sleep(1); | ||
header("Content-Type: text/css"); | ||
fpassthru(fopen('/Users/andreyvit/dev/products/LiveReload/js/test/html/delayed/test.css', 'rb')); |