Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

…wnloads IE 7/8
  • Loading branch information...
commit 49e9c7df51d67249b60e961106468fae6cebd36d 1 parent 9851454
Arnout Kazemier authored March 07, 2013
17  client/index.js
... ...
@@ -1,6 +1,7 @@
1 1
 'use strict';
2 2
 
3 3
 var HashRing = require('hashring')
  4
+  , path = require('path')
4 5
   , undefined;
5 6
 
6 7
 /**
@@ -78,8 +79,14 @@ function Sync(versions, server, options) {
78 79
  */
79 80
 Sync.prototype.tag = function tag(url) {
80 81
   var server = this.hashring.get(url);
81  
-
82 82
   if (!server) return url;
  83
+
  84
+  // In IE7 - 8 a protocol relative stylesheet will cause a double download,
  85
+  // make sure that our server isn't relative by forcing HTTPS.
  86
+  if (server.charAt(0) === '/' && path.extname(url) === '.css') {
  87
+    server = 'https:'+ server;
  88
+  }
  89
+
83 90
   return this.prefix(server) + url;
84 91
 };
85 92
 
@@ -114,9 +121,7 @@ Sync.prototype.initialize = function initialize() {
114 121
   if (this.get('auth')) url += '?auth='+ this.get('auth');
115 122
 
116 123
   // Check if we need to prefix the server
117  
-  if (url.charAt(0) === '/' && url.charAt(1) === '/') {
118  
-    url = 'https:'+ url;
119  
-  }
  124
+  if (url.charAt(0) === '/') url = 'https:'+ url;
120 125
 
121 126
   /**
122 127
    * They see me pollin, they hatin.
@@ -193,9 +198,7 @@ Sync.prototype.version = function version(number, callback) {
193 198
   if (this.get('auth')) url += '?auth='+ this.get('auth');
194 199
 
195 200
   // Check if we need to prefix the server
196  
-  if (url.charAt(0) === '/' && url.charAt(1) === '/') {
197  
-    url = 'https:'+ url;
198  
-  }
  201
+  if (url.charAt(0) === '/') url = 'https:'+ url;
199 202
 
200 203
   this.request({
201 204
       uri: url
9  test/client.test.js
@@ -114,6 +114,15 @@ describe('versions.connect()', function () {
114 114
         expect(tag).to.equal('http://lolcathost:'+ port +'/versions:0.0.0/css/base.css');
115 115
       }
116 116
     });
  117
+
  118
+    it('forces https for server relative protcol css files', function () {
  119
+      var client = require('../').clone().connect('//localhost:8888');
  120
+
  121
+      expect(client.tag('/foo.png')).to.equal('//localhost:8888/versions:0.0.0/foo.png');
  122
+      expect(client.tag('/foo.css')).to.equal('https://localhost:8888/versions:0.0.0/foo.css');
  123
+
  124
+      client.end();
  125
+    });
117 126
   });
118 127
 
119 128
   describe('#prefix', function () {

0 notes on commit 49e9c7d

Please sign in to comment.
Something went wrong with that request. Please try again.