Merge lp:~davidc3/developer-ubuntu-com/faster-404-redirects into lp:developer-ubuntu-com

Proposed by David Callé on 2016-05-10
Status: Merged
Merged at revision: 219
Proposed branch: lp:~davidc3/developer-ubuntu-com/faster-404-redirects
Merge into: lp:developer-ubuntu-com
Diff against target: 33 lines (+1/-17)
1 file modified
templates/404.html (+1/-17)
To merge this branch: bzr merge lp:~davidc3/developer-ubuntu-com/faster-404-redirects
Reviewer Review Type Date Requested Status
Daniel Holbach (community) 2016-05-10 Approve on 2016-05-10
Review via email: mp+294240@code.launchpad.net

Commit Message

Make JS redirects faster by not checking for target existence.

Description of the Change

Make JS redirects faster by not checking for target existence.

To post a comment you must log in.
Daniel Holbach (dholbach) wrote :

Looks good to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'templates/404.html'
2--- templates/404.html 2016-04-05 10:03:09 +0000
3+++ templates/404.html 2016-05-10 13:10:13 +0000
4@@ -24,28 +24,12 @@
5 {'from':'/start/ubuntu-sdk/', 'to':'/phone/platform/sdk/'},
6 {'from':'/start/', 'to':'/phone/'}]
7
8- function returnStatus(req, status) {
9- if(status == 200) {
10- window.location = new_path
11- }
12- }
13-
14- function fetchStatus(address) {
15- var client = new XMLHttpRequest();
16- client.onreadystatechange = function() {
17- if(this.readyState == 4)
18- returnStatus(this, this.status);
19- }
20- client.open("HEAD", address);
21- client.send();
22- }
23-
24 for (var i = 0; i < move.length; i++) {
25 var m = "/" + "{{ lang }}" + move[i]['from']
26 var t = "/" + "{{ lang }}" + move[i]['to']
27 if (path.lastIndexOf(m, 0) === 0) {
28 var new_path = path.replace(m, t);
29- fetchStatus(new_path)
30+ window.location = new_path
31 break;
32 }
33 }

Subscribers

People subscribed via source and target branches