Skip to content

Commit 6075263

Browse files
committed
make browser.setUrl more efficient
- browser should remember the last value retrieved via browser.getUrl - browser should update window.location only if the new value is different from the current window.location value
1 parent bb27c91 commit 6075263

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/Browser.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ var XHR_HEADERS = {
3434
function Browser(window, document, body, XHR, $log) {
3535
var self = this,
3636
location = window.location,
37-
setTimeout = window.setTimeout;
37+
setTimeout = window.setTimeout,
38+
lastLocationUrl;
3839

3940
self.isMock = false;
4041

@@ -200,10 +201,14 @@ function Browser(window, document, body, XHR, $log) {
200201
* Sets browser's url
201202
*/
202203
self.setUrl = function(url) {
203-
var existingURL = location.href;
204+
205+
var existingURL = lastLocationUrl;
204206
if (!existingURL.match(/#/)) existingURL += '#';
205207
if (!url.match(/#/)) url += '#';
206-
location.href = url;
208+
if (existingURL != url) {
209+
console.log('$browser.setUrl', url);
210+
location.href = url;
211+
}
207212
};
208213

209214
/**
@@ -218,7 +223,7 @@ function Browser(window, document, body, XHR, $log) {
218223
* @returns {string} Browser's url
219224
*/
220225
self.getUrl = function() {
221-
return location.href;
226+
return lastLocationUrl = location.href;
222227
};
223228

224229

0 commit comments

Comments
 (0)