Permalink
Browse files

[fix] Don't use relative protocols for css files, it causes double do…

…wnloads IE 7/8
  • Loading branch information...
1 parent 9851454 commit 49e9c7df51d67249b60e961106468fae6cebd36d @3rd-Eden committed Mar 7, 2013
Showing with 19 additions and 7 deletions.
  1. +10 −7 client/index.js
  2. +9 −0 test/client.test.js
View
@@ -1,6 +1,7 @@
'use strict';
var HashRing = require('hashring')
+ , path = require('path')
, undefined;
/**
@@ -78,8 +79,14 @@ function Sync(versions, server, options) {
*/
Sync.prototype.tag = function tag(url) {
var server = this.hashring.get(url);
-
if (!server) return url;
+
+ // In IE7 - 8 a protocol relative stylesheet will cause a double download,
+ // make sure that our server isn't relative by forcing HTTPS.
+ if (server.charAt(0) === '/' && path.extname(url) === '.css') {
+ server = 'https:'+ server;
+ }
+
return this.prefix(server) + url;
};
@@ -114,9 +121,7 @@ Sync.prototype.initialize = function initialize() {
if (this.get('auth')) url += '?auth='+ this.get('auth');
// Check if we need to prefix the server
- if (url.charAt(0) === '/' && url.charAt(1) === '/') {
- url = 'https:'+ url;
- }
+ if (url.charAt(0) === '/') url = 'https:'+ url;
/**
* They see me pollin, they hatin.
@@ -193,9 +198,7 @@ Sync.prototype.version = function version(number, callback) {
if (this.get('auth')) url += '?auth='+ this.get('auth');
// Check if we need to prefix the server
- if (url.charAt(0) === '/' && url.charAt(1) === '/') {
- url = 'https:'+ url;
- }
+ if (url.charAt(0) === '/') url = 'https:'+ url;
this.request({
uri: url
View
@@ -114,6 +114,15 @@ describe('versions.connect()', function () {
expect(tag).to.equal('http://lolcathost:'+ port +'/versions:0.0.0/css/base.css');
}
});
+
+ it('forces https for server relative protcol css files', function () {
+ var client = require('../').clone().connect('//localhost:8888');
+
+ expect(client.tag('/foo.png')).to.equal('//localhost:8888/versions:0.0.0/foo.png');
+ expect(client.tag('/foo.css')).to.equal('https://localhost:8888/versions:0.0.0/foo.css');
+
+ client.end();
+ });
});
describe('#prefix', function () {

0 comments on commit 49e9c7d

Please sign in to comment.