Skip to content
This repository was archived by the owner on Sep 10, 2022. It is now read-only.

Commit a177545

Browse files
committed
Merge pull request #44 from GoogleChrome/styles-seperation
Making it so that styles are added to the head of the document
2 parents dad153b + 418ca74 commit a177545

File tree

4 files changed

+37
-5
lines changed

4 files changed

+37
-5
lines changed

gulp-tasks/service-worker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var swPrecache = require('sw-precache');
2424
var packageName = JSON.parse(fs.readFileSync('./package.json', 'utf8')).name;
2525

2626
gulp.task('service-worker:watch', function(cb) {
27-
gulp.watch(GLOBAL.config.src + '/**/*.*', ['service-worker']);
27+
gulp.watch(GLOBAL.config.dest + '/**/*.*', ['service-worker']);
2828
gulp.watch(GLOBAL.config.src + '/../server/views/**/*.*',
2929
['service-worker']);
3030
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "app-shell",
3-
"version": "0.1.175",
3+
"version": "0.1.177",
44
"private": true,
55
"license": "Apache Version 2.0",
66
"engines": {
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
<style type="text/css">{{{inlineStyles}}}</style>
1+
<style class="js-partial-styles" type="text/css">{{{inlineStyles}}}</style>
22

3+
<div class="js-partial-content">
34
{{{ body }}}
45

56
{{#each remoteScripts}}
67
<script src="{{this}}" async></script>
78
{{~/each}}
9+
</div>

src/scripts/controller/ActivityController.js

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,26 @@ export default class ActivityController {
2727
})
2828
.then((responseText) => {
2929
if (responseText !== null) {
30-
this.mainContainer.innerHTML = responseText;
30+
/**
31+
* NOTE: We could move the script tags in the partial to the
32+
* bottom of the body, but I don't think it'll change browser
33+
* behaviour so it should be fine to inline the script tag in
34+
* the main element.
35+
**/
36+
37+
// Parse the response string
38+
var parser = new DOMParser();
39+
var partialElement =
40+
parser.parseFromString(responseText, 'text/html');
41+
42+
// Add style element to the document head
43+
var styleElement = partialElement.querySelector('.js-partial-styles');
44+
document.head.appendChild(styleElement);
45+
46+
// Add content from partial to page
47+
var contentElement =
48+
partialElement.querySelector('.js-partial-content');
49+
this.mainContainer.innerHTML = contentElement.innerHTML;
3150
}
3251

3352
// Hide loading dialog
@@ -39,7 +58,18 @@ export default class ActivityController {
3958
}
4059

4160
onFinish() {
42-
console.log('onFinish: ', this.path);
61+
console.log('onFinish');
62+
// Remove any existing styles
63+
var insertedStyles =
64+
document.querySelector('.js-partial-styles');
65+
if (insertedStyles) {
66+
document.head.removeChild(insertedStyles);
67+
}
68+
69+
// Remove the current content
70+
while (this.mainContainer.firstChild) {
71+
this.mainContainer.removeChild(this.mainContainer.firstChild);
72+
}
4373
}
4474

4575
show404() {

0 commit comments

Comments
 (0)