Skip to content

Commit e71891f

Browse files
committed
Improved performance for very large pages
1 parent 1d9d678 commit e71891f

File tree

5 files changed

+47
-34
lines changed

5 files changed

+47
-34
lines changed

material/assets/javascripts/bundle.3900859e.min.js

Lines changed: 0 additions & 29 deletions
This file was deleted.

material/assets/javascripts/bundle.467223ff.min.js

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

material/assets/javascripts/bundle.3900859e.min.js.map renamed to material/assets/javascripts/bundle.467223ff.min.js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

material/base.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@
214214
</script>
215215
{% endblock %}
216216
{% block scripts %}
217-
<script src="{{ 'assets/javascripts/bundle.3900859e.min.js' | url }}"></script>
217+
<script src="{{ 'assets/javascripts/bundle.467223ff.min.js' | url }}"></script>
218218
{% for path in config["extra_javascript"] %}
219219
<script src="{{ path | url }}"></script>
220220
{% endfor %}

src/assets/javascripts/components/content/code/_/index.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ import {
2828
defer,
2929
distinctUntilChanged,
3030
distinctUntilKeyChanged,
31+
filter,
3132
finalize,
3233
map,
3334
mergeWith,
3435
switchMap,
36+
take,
3537
takeLast,
3638
takeUntil,
3739
tap
@@ -40,7 +42,8 @@ import {
4042
import { feature } from "~/_"
4143
import {
4244
getElementContentSize,
43-
watchElementSize
45+
watchElementSize,
46+
watchElementVisibility
4447
} from "~/browser"
4548
import { renderClipboardButton } from "~/templates"
4649

@@ -153,7 +156,9 @@ export function mountCodeBlock(
153156
el: HTMLElement, options: MountOptions
154157
): Observable<Component<CodeBlock | Annotation>> {
155158
const { matches: hover } = matchMedia("(hover)")
156-
return defer(() => {
159+
160+
/* Defer mounting of code block - see https://bit.ly/3vHVoVD */
161+
const factory$ = defer(() => {
157162
const push$ = new Subject<CodeBlock>()
158163
push$.subscribe(({ scrollable }) => {
159164
if (scrollable && hover)
@@ -213,4 +218,12 @@ export function mountCodeBlock(
213218
map(state => ({ ref: el, ...state }))
214219
)
215220
})
221+
222+
/* Mount code block on first sight */
223+
return watchElementVisibility(el)
224+
.pipe(
225+
filter(visible => visible),
226+
take(1),
227+
switchMap(() => factory$)
228+
)
216229
}

0 commit comments

Comments
 (0)