diff --git a/core/js/update.js b/core/js/update.js
new file mode 100644
index 0000000000000000000000000000000000000000..8ab02bbf9350c3bdeb594a49561c6ae6499b34c2
--- /dev/null
+++ b/core/js/update.js
@@ -0,0 +1,23 @@
+$(document).ready(function () {
+	var updateEventSource = new OC.EventSource(OC.webroot+'/core/ajax/update.php');
+	updateEventSource.listen('success', function(message) {
+		$('<span>').append(message).append('<br />').appendTo($('.update'));
+	});
+	updateEventSource.listen('error', function(message) {
+		$('<span>').addClass('error').append(message).append('<br />').appendTo($('.update'));
+	});
+	updateEventSource.listen('failure', function(message) {
+		$('<span>').addClass('error').append(message).append('<br />').appendTo($('.update'));
+		$('<span>')
+		.addClass('error bold')
+		.append('<br />')
+		.append(t('core', 'The update was unsuccessful. Please report this issue to the <a href="https://github.com/owncloud/core/issues" target="_blank">ownCloud community</a>.'))
+		.appendTo($('.update'));
+	});
+	updateEventSource.listen('done', function(message) {
+		$('<span>').addClass('bold').append('<br />').append(t('core', 'The update was successful. Redirecting you to ownCloud now.')).appendTo($('.update'));
+		setTimeout(function () {
+			window.location.href = OC.webroot;
+		}, 3000);
+	});
+});
\ No newline at end of file
diff --git a/core/templates/update.php b/core/templates/update.php
index c65230db0d68d6094fbd4c12b3f7add130994a83..ae714dcfb92211849acd7dbde483e4e2f246bdd6 100644
--- a/core/templates/update.php
+++ b/core/templates/update.php
@@ -3,28 +3,3 @@
 		<?php echo $l->t('Updating ownCloud to version %s, this may take a while.', array($_['version'])); ?><br /><br />
 	</li>
 </ul>
-<script>
-	$(document).ready(function () {
-		var updateEventSource = new OC.EventSource(OC.webroot+'/core/ajax/update.php');
-		updateEventSource.listen('success', function(message) {
-			$('<span>').append(message).append('<br />').appendTo($('.update'));
-		});
-		updateEventSource.listen('error', function(message) {
-			$('<span>').addClass('error').append(message).append('<br />').appendTo($('.update'));
-		});
-		updateEventSource.listen('failure', function(message) {
-			$('<span>').addClass('error').append(message).append('<br />').appendTo($('.update'));
-			$('<span>')
-				.addClass('error bold')
-				.append('<br />')
-				.append(t('core', 'The update was unsuccessful. Please report this issue to the <a href="https://github.com/owncloud/core/issues" target="_blank">ownCloud community</a>.'))
-				.appendTo($('.update'));
-		});
-		updateEventSource.listen('done', function(message) {
-			$('<span>').addClass('bold').append('<br />').append(t('core', 'The update was successful. Redirecting you to ownCloud now.')).appendTo($('.update'));
-			setTimeout(function () {
-				window.location.href = OC.webroot;
-			}, 3000);
-		});
-	});
-</script>
\ No newline at end of file
diff --git a/lib/base.php b/lib/base.php
index aff3e1d5a11fb9c4700bd0d4f93cfedcad5b91a1..f9818d3514e730ab52cc723fc6d9f9657927f97b 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -259,6 +259,7 @@ class OC
 				if ($showTemplate && !OC_Config::getValue('maintenance', false)) {
 					OC_Config::setValue('maintenance', true);
 					OC_Log::write('core', 'starting upgrade from ' . $installedVersion . ' to ' . $currentVersion, OC_Log::DEBUG);
+					OC_Util::addscript('update');
 					$tmpl = new OC_Template('', 'update', 'guest');
 					$tmpl->assign('version', OC_Util::getVersionString());
 					$tmpl->printPage();
@@ -429,8 +430,6 @@ class OC
 		self::checkSSL();
 		self::initSession();
 		self::initTemplateEngine();
-		self::checkMaintenanceMode();
-		self::checkUpgrade();
 
 		$errors = OC_Util::checkServer();
 		if (count($errors) > 0) {
@@ -570,10 +569,13 @@ class OC
 			return;
 		}
 
+		// Check if ownCloud is installed or in maintenance (update) mode
 		if (!OC_Config::getValue('installed', false)) {
 			require_once 'core/setup.php';
 			exit();
 		}
+		self::checkMaintenanceMode();
+		self::checkUpgrade();
 		
 		// Handle redirect URL for logged in users
 		if (isset($_REQUEST['redirect_url']) && OC_User::isLoggedIn()) {