History

Improve app loading sequence

Thibaut Courouble committed 9 years ago

Commit 74286451 parent 9e9735710 files · +44 −65Browse files

Unified · Split

10 files
  1. assets/javascripts/app/app.coffee +6 −13
  2. assets/stylesheets/components/_app.scss +1 −29
  3. assets/stylesheets/components/_content.scss +18 −5
  4. assets/stylesheets/components/_mobile.scss +4 −3
  5. assets/stylesheets/global/_base.scss +1 −1
  6. assets/stylesheets/global/_variables-dark.scss +0 −1
  7. assets/stylesheets/global/_variables.scss +0 −1
  8. test/app_test.rb +1 −1
  9. views/index.erb +7 −6
  10. views/other.erb +6 −5
assets/javascripts/app/app.coffee+6−13
@@ -10,7 +10,6 @@ · 9 unmodified lines
1010 init: ->
1111 try @initErrorTracking() catch
1212 return unless @browserCheck()
13− @showLoading()
1413
1514 @el = $('._app')
1615 @localStorage = new LocalStorageStore
@@ -38,8 +37,8 @@ · 21 unmodified lines
3837
3938 browserCheck: ->
4039 return true if @isSupportedBrowser()
41− document.body.className = ''
4240 document.body.innerHTML = app.templates.unsupportedBrowser
41+ @hideLoadingScreen()
4342 false
4443
4544 initErrorTracking: ->
@@ -103,7 +102,7 @@ · 57 unmodified lines
103102 @initDoc(doc) for doc in @docs.all()
104103 @trigger 'ready'
105104 @router.start()
106− @hideLoading()
105+ @hideLoadingScreen()
107106 setTimeout =>
108107 @welcomeBack() unless @doc
109108 @removeEvent 'ready bootError'
@@ -181,15 +180,9 @@ · 71 unmodified lines
181180 new app.views.Tip(tip)
182181 return
183182
184− showLoading: ->
185− document.body.classList.remove '_noscript'
186− document.body.classList.add '_loading'
187− return
188−
189− hideLoading: ->
183+ hideLoadingScreen: ->
190184 document.body.classList.add '_overlay-scrollbars' if $.overlayScrollbarsEnabled()
191− document.body.classList.remove '_booting'
192− document.body.classList.remove '_loading'
185+ document.documentElement.classList.remove '_booting'
193186 return
194187
195188 indexHost: ->
@@ -199,7 +192,7 @@ · 3 unmodified lines
199192
200193 onBootError: (args...) ->
201194 @trigger 'bootError'
202− @hideLoading()
195+ @hideLoadingScreen()
203196 return
204197
205198 onQuotaExceeded: ->
@@ -221,7 +214,7 @@ · 15 unmodified lines
221214 @onInjectionError()
222215 else if @isAppError args...
223216 @previousErrorHandler? args...
224− @hideLoading()
217+ @hideLoadingScreen()
225218 @errorNotif or= new app.views.Notif 'Error'
226219 @errorNotif.show()
227220 return
assets/stylesheets/components/_app.scss+1−29
@@ -3,13 +3,11 @@ · 2 unmodified lines
33 z-index: 1;
44 height: 100%;
55 overflow: hidden;
6− background: $contentBackground;
76 -webkit-transition: opacity .2s;
87 transition: opacity .2s;
98 @extend %border-box;
109
11− ._booting > & { opacity: 0; }
12− ._noscript > & { display: none; }
10+ ._booting & { opacity: 0; }
1311
1412 ._max-width & {
1513 margin: 0 auto;
@@ -17,29 +15,3 @@ · 1 unmodified line
1715 box-shadow: 1px 0 $headerBorder, -1px 0 $headerBorder;
1816 }
1917 }
20−
21−._booting {
22− opacity: 0;
23−
24− &._loading, &._loading:before { opacity: 1; }
25−
26− &:before {
27− content: 'Loading\2026';
28− position: absolute;
29− top: 50%;
30− left: 0;
31− right: 0;
32− line-height: 1;
33− margin-top: -.6em;
34− font-size: 4rem;
35− font-weight: 300;
36− letter-spacing: -.125rem;
37− color: $loadingText;
38− text-align: center;
39− opacity: 0;
40− -webkit-transition: opacity .1s .3s;
41− transition: opacity .1s .3s;
42− }
43−}
44−
45−._noscript { opacity: 1; }
assets/stylesheets/components/_content.scss+18−5
@@ -43,9 +43,24 @@ · 42 unmodified lines
4343 }
4444 }
4545
46+%loading {
47+ content: 'Loading\2026';
48+ position: absolute;
49+ top: 50%;
50+ left: 0;
51+ right: 0;
52+ line-height: 1;
53+ margin-top: -.6em;
54+ font-size: 4rem;
55+ font-weight: 300;
56+ letter-spacing: -.125rem;
57+ color: $loadingText;
58+ text-align: center;
59+ cursor: default;
60+}
61+
4662 ._content-loading:before {
47− opacity: 1;
48− @extend ._booting:before;
63+ @extend %loading;
4964 }
5065
5166 //
@@ -54,9 +69,7 @@ · 2 unmodified lines
5469
5570 ._splash-title {
5671 color: $splashText;
57− cursor: default;
58− opacity: 1;
59− @extend ._booting:before, %user-select-none;
72+ @extend %loading, %user-select-none;
6073 }
6174
6275 //
assets/stylesheets/components/_mobile.scss+4−3
@@ -4,7 +4,6 @@ · 3 unmodified lines
44
55 ._mobile {
66 font-size: 100%;
7− background: $contentBackground;
87
98 ._hide-on-mobile { display: none; }
109
@@ -12,7 +11,9 @@ · 1 unmodified line
1211
1312 body { -ms-overflow-style: -ms-autohiding-scrollbar; }
1413
15− ._app, ._content { overflow: visible; }
14+ &:not(._booting) {
15+ ._app, ._content { overflow: visible; }
16+ }
1617
1718 ._container {
1819 margin: 0;
@@ -28,7 +29,7 @@ · 9 unmodified lines
2829 &:before { content: none; }
2930 }
3031
31− ._booting:before, ._content-loading:before { font-size: 3rem; }
32+ ._content-loading:before, ._splash-title { font-size: 3rem; }
3233
3334 ._header { position: fixed; }
3435
assets/stylesheets/global/_base.scss+1−1
@@ -1,7 +1,7 @@
11 html {
22 height: 100%;
33 font-size: 100%;
4− background: $documentBackground;
4+ background: $contentBackground;
55
66 @media #{$mediumScreen} { font-size: 93.75%; }
77 }
assets/stylesheets/global/_variables-dark.scss+0−1
@@ -11,7 +11,6 @@ $sidebarWidth: 20rem; · 10 unmodified lines
1111 $sidebarMediumWidth: 16rem;
1212
1313 $contentBackground: #33373a;
14−$documentBackground: $contentBackground;
1514
1615 $textColor: #cbd0d0;
1716 $textColorLight: #9da5ad;
assets/stylesheets/global/_variables.scss+0−1
@@ -11,7 +11,6 @@ $sidebarWidth: 20rem; · 10 unmodified lines
1111 $sidebarMediumWidth: 16rem;
1212
1313 $contentBackground: #fff;
14−$documentBackground: #fafafa;
1514
1615 $textColor: #333;
1716 $textColorLight: #666;
test/app_test.rb+1−1
@@ -43,7 +43,7 @@ class AppTest < MiniTest::Spec · 42 unmodified lines
4343 it "sets layout from cookie" do
4444 set_cookie('layout=foo')
4545 get '/'
46− assert_includes last_response.body, '<body class="_booting _noscript foo">'
46+ assert_includes last_response.body, '<body class="foo">'
4747 end
4848 end
4949
views/index.erb+7−6
@@ -1,5 +1,5 @@
11 <!DOCTYPE html>
2−<html<%= ' manifest="/manifest.appcache"' if App.production? %> prefix="og: http://ogp.me/ns#" lang="en">
2+<html<%= ' manifest="/manifest.appcache"' if App.production? %> prefix="og: http://ogp.me/ns#" lang="en" class="_booting">
33 <head>
44 <meta charset="utf-8">
55 <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no,shrink-to-fit=no">
@@ -31,11 +31,12 @@ · 25 unmodified lines
3131 <link rel="apple-touch-icon" sizes="160x160" href="<%= App.cdn_origin %>/images/apple-icon-160.png">
3232 <link rel="mask-icon" href="<%= App.cdn_origin %>/images/webkit-mask-icon.svg" color="#398df0">
3333 <link rel="stylesheet" href="<%= main_stylesheet_path %>" data-alt="<%= alternate_stylesheet_path %>">
34− <%= javascript_tag 'application', asset_host: false %>
35− <%= javascript_tag 'docs' %><% unless App.production? %>
36− <%= javascript_tag 'debug' %><% end %>
3734 </head>
38−<body class="_booting _noscript<%= " #{app_layout}" if app_layout %>">
35+<body<%= %w( class="#{app_layout}") if app_layout %>>
3936 <noscript class="_fail">DevDocs requires JavaScript to run.</noscript>
40−<%= erb :app %></body>
37+<%= erb :app -%>
38+<%= javascript_tag 'application', asset_host: false %>
39+<%= javascript_tag 'docs' %><% unless App.production? %>
40+<%= javascript_tag 'debug' %><% end %>
41+</body>
4142 </html>
views/other.erb+6−5
@@ -1,5 +1,5 @@
11 <!DOCTYPE html>
2−<html lang="en">
2+<html lang="en" class="_booting">
33 <head>
44 <meta charset="utf-8">
55 <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
@@ -12,10 +12,11 @@ · 6 unmodified lines
1212 <link rel="icon" type="image/x-icon" href="<%= App.cdn_origin %>/favicon.ico">
1313 <link rel="search" type="application/opensearchdescription+xml" href="/opensearch.xml" title="Search DevDocs">
1414 <link rel="stylesheet" href="<%= main_stylesheet_path %>" data-alt="<%= alternate_stylesheet_path %>">
15− <%= javascript_tag 'application', asset_host: false %><% unless App.production? %>
16− <%= javascript_tag 'debug' %><% end %>
1715 </head>
18−<body class="_booting _noscript<%= " #{app_layout}" if app_layout %>" data-doc="<%= CGI::escape_html @doc.to_json %>">
16+<body<%= %w( class="#{app_layout}") if app_layout %> data-doc="<%= CGI::escape_html @doc.to_json %>">
1917 <noscript class="_fail">DevDocs requires JavaScript to run.</noscript>
20−<%= erb :app %></body>
18+<%= erb :app -%>
19+<%= javascript_tag 'application', asset_host: false %><% unless App.production? %>
20+<%= javascript_tag 'debug' %><% end %>
21+</body>
2122 </html>