Skip to content

Commit

Permalink
Improved performance for very large pages
Browse files Browse the repository at this point in the history
  • Loading branch information
squidfunk committed Mar 6, 2022
1 parent 1d9d678 commit e71891f
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 34 deletions.
29 changes: 0 additions & 29 deletions material/assets/javascripts/bundle.3900859e.min.js

This file was deleted.

29 changes: 29 additions & 0 deletions material/assets/javascripts/bundle.467223ff.min.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion material/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
</script>
{% endblock %}
{% block scripts %}
<script src="{{ 'assets/javascripts/bundle.3900859e.min.js' | url }}"></script>
<script src="{{ 'assets/javascripts/bundle.467223ff.min.js' | url }}"></script>
{% for path in config["extra_javascript"] %}
<script src="{{ path | url }}"></script>
{% endfor %}
Expand Down
17 changes: 15 additions & 2 deletions src/assets/javascripts/components/content/code/_/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ import {
defer,
distinctUntilChanged,
distinctUntilKeyChanged,
filter,
finalize,
map,
mergeWith,
switchMap,
take,
takeLast,
takeUntil,
tap
Expand All @@ -40,7 +42,8 @@ import {
import { feature } from "~/_"
import {
getElementContentSize,
watchElementSize
watchElementSize,
watchElementVisibility
} from "~/browser"
import { renderClipboardButton } from "~/templates"

Expand Down Expand Up @@ -153,7 +156,9 @@ export function mountCodeBlock(
el: HTMLElement, options: MountOptions
): Observable<Component<CodeBlock | Annotation>> {
const { matches: hover } = matchMedia("(hover)")
return defer(() => {

/* Defer mounting of code block - see https://bit.ly/3vHVoVD */
const factory$ = defer(() => {
const push$ = new Subject<CodeBlock>()
push$.subscribe(({ scrollable }) => {
if (scrollable && hover)
Expand Down Expand Up @@ -213,4 +218,12 @@ export function mountCodeBlock(
map(state => ({ ref: el, ...state }))
)
})

/* Mount code block on first sight */
return watchElementVisibility(el)
.pipe(
filter(visible => visible),
take(1),
switchMap(() => factory$)
)
}

0 comments on commit e71891f

Please sign in to comment.