Skip to content

Fix render-blocking widget script#18

Open
filip1 wants to merge 1 commit intowebvariants:masterfrom
filip1:patch-2
Open

Fix render-blocking widget script#18
filip1 wants to merge 1 commit intowebvariants:masterfrom
filip1:patch-2

Conversation

@filip1
Copy link

@filip1 filip1 commented Aug 24, 2020

The widget embed code prevents the embedding page from rendering while the widget script is loading. Instead, the script can be loaded asyncronously while showing a loading animation.

An example of an asynchronous embed code that loads widget 9123 from policat.org:

<div id="policat_9123"><div class="policat-loading"></div></div>
<script type="text/javascript">window.policat_target_id_9123 = "policat_9123";</script>
<script type="text/javascript" src="https://www.policat.org/api/js/widget/9123" async="true"></script>
<style>
.policat-loading {
    position: relative;
    height: 1em;
    text-align: center;
}
@keyframes policatspin {
  to {transform: rotate(360deg);}
}
.policat-loading::after {
    content: '';
    box-sizing: border-box;
    position: absolute;
    top: .33em;
    width: 1em;
    height: 1em;
    margin-left: 1em;
    border-radius: 50%;
    border-top: 2px solid #333;
    border-right: 2px solid transparent;
    animation: policatspin .8s linear infinite;
}
</style>

The widget embed code prevents the embedding page from rendering while the widget script is loading. Instead, the script can be loaded asyncronously while showing a loading animation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant