diff --git a/.travis-test-riot.sh b/.travis-test-riot.sh
index 87200871a5..eeba4d0b7e 100755
--- a/.travis-test-riot.sh
+++ b/.travis-test-riot.sh
@@ -9,16 +9,9 @@ set -ev
 RIOT_WEB_DIR=riot-web
 REACT_SDK_DIR=`pwd`
 
-curbranch="${TRAVIS_PULL_REQUEST_BRANCH:-$TRAVIS_BRANCH}"
-echo "Determined branch to be $curbranch"
-
-git clone https://github.com/vector-im/riot-web.git \
-    "$RIOT_WEB_DIR"
-
+scripts/fetchdep.sh vector-im riot-web
 cd "$RIOT_WEB_DIR"
 
-git checkout "$curbranch" || git checkout develop
-
 mkdir node_modules
 npm install
 
diff --git a/.travis.yml b/.travis.yml
index 954f14a4da..ec07243a28 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -15,6 +15,5 @@ addons:
     chrome: stable
 install:
     - npm install
-    - (cd node_modules/matrix-js-sdk && npm install)
 script:
     ./scripts/travis.sh
diff --git a/scripts/fetchdep.sh b/scripts/fetchdep.sh
new file mode 100755
index 0000000000..424a8b034c
--- /dev/null
+++ b/scripts/fetchdep.sh
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+set -e
+
+org="$1"
+repo="$2"
+
+curbranch="${TRAVIS_PULL_REQUEST_BRANCH:-$TRAVIS_BRANCH}"
+echo "Determined branch to be $curbranch"
+
+git clone https://github.com/$org/$repo.git $repo --branch "$curbranch" || git clone https://github.com/$org/$repo.git $repo --branch develop
+
diff --git a/scripts/travis.sh b/scripts/travis.sh
index c4a06c1bd1..48410ea904 100755
--- a/scripts/travis.sh
+++ b/scripts/travis.sh
@@ -2,6 +2,14 @@
 
 set -ex
 
+scripts/fetchdep.sh matrix-org matrix-js-sdk
+rm -r node_modules/matrix-js-sdk || true
+ln -s ../matrix-js-sdk node_modules/matrix-js-sdk
+
+cd matrix-js-sdk
+npm install
+cd ..
+
 npm run test
 ./.travis-test-riot.sh