Simple And Easy To Use Tool To Detect Website Loading Progress | Siteloader

SiteLoader is a simple and easy-to-use website loading progress detection tool that can help you quickly achieve a real page loading effect. [一个简单易用的网站加载进度检测小工具,可以帮助您快速实现页面的真实加载效果] It monitors photo, video, and audio loading progress, then runs a custom function when all assets are fully loaded. Perfect for any developer looking to perfect the user experience through careful management of load notes.

This library can calculate the total loading progress of all page element resources (image/video/audio) you pass. This progress will vary from 0 to 100. You can use the progress event to make your settings each time the progress changes. A callback function, and you can get the value of the current progress through this callback function.

And when all the resources you set to count are loaded, the corresponding event will be triggered, and you can set the corresponding callback function through this event, so that it is easy to implement some custom code to implement some page behaviors, such as loading hide, page rendering, and so on.

There are two load statistics modes

  • Overall load – the most frequently used load statistics mode, all resources that need load statistics are loaded together as a whole, and the load order follows the default mechanism of the browser.
  • Loading in stages All resources that need to be calculated will be divided into multiple stages, and the resources in each stage will be loaded in sequence. For example, after the resources are loaded in the first stage, the resources in the second stage will be loaded. Resources at each stage After the upload is completed, the corresponding event will be triggered, and you can execute your own code in the event.

Must Read: A Lightweight JavaScript Library For Accurate Web Loading Progress | realprogress.js

How to make use of it:

1. Install and import the Siteloader tool.

# NPM
$ npm i siteloader
import SiteLoader from 'siteloader'
<!-- OR -->
<script src="dist/sl.umd.js"></script>

2. Configure SiteLoader and select Images, Video, or Audio to monitor upload progress.

const sl = new SiteLoader(
  [
    {
      sources: [
        {
          sourceType: 'image',
          selectors: ['.selected', '.selected-2']
        },
        {
          sourceType: 'media',
          selectors: ['#video']
        },
        {
          sourceType: 'media',
          selectors: ['#audio']
        }
      ]
    }
  ]
)

3. Separate resources into phases to sequence loading and trigger events.

const sl = new SiteLoader(
  [
    // stage1
    {
      stageName: 'stage1',
      sources: [{
        sourceType: 'image',
        selectors: ['.selected']
      }]
    },
    // stage2 
    {
      stageName: 'stage2',
      sources: [
        {
          sourceType: 'media',
          selectors: ['#audio']
        },
        {
          sourceType: 'media',
          selectors: ['#video']
        }
      ]
    }
  ]
)

4. Activate the side loader.

sl.startLoad()

5. Event handlers.

sl.addEventListener('progress', (e) => {
  console.log(e.progress, '...')
})
sl.addEventListener('stage1',  () => {
  console.log('Stage 1 has been loaded')
})
sl.addEventListener('countComplete', () => {
  console.log('end of count')
})
sl.addEventListener('trueLoadFinish', () => {
  console.log('All assets are loaded')
})

See Demo And Download

siteloader

Official Website(Yinglinhan): Click Here

This superior jQuery/javascript plugin is developed by Yinglinhan. For extra advanced usage, please go to the official website.

Related Posts

drag-drop-file-5x5-jq-uploader

Responsive Drag and Drop File Uploader/Download Plugin | 5x5_jq_uploader

5x5_jq_uploader plugin can be used to instantly create a drop file area and file queue with a little bit of preparation. Bootstrap is used for responsive planning…

Bootstrap-Dark-Mode

Stylesheet For Implementing Dark Mode with Bootstrap

Bootstrap Dark Mode provides a style sheet and two texts that allow you to implement Dark Mode on your website. Initially loaded based on user preferences, can…

responsive-navigation-menu

Multi-purpose Navigation Menu for Javascript Library | jQuery Corenav

coreNavigation is a multipurpose navigation menu for a jquery based javascript library, comes with more style, and is easy to integrate. 11 Default Menu 2 Responsive Navigation…

Simple-Multi-Select-Dropdown-Pure-Vanilla-Javascript

Simple Multi-Select Dropdown Pure Vanilla Javascript | multiSelect.js

MultiSelect.js is a simple, clean, and progressive JavaScript library designed for easy integration with any type of project or system. The design was heavily influenced by the…

Confetti-Falling-Animation-Effect-party

Confetti Falling Animation Effect In JavaScript | party.js

Party.js is a JavaScript library to brighten user site experience with visual effects! Celebrate success with dom confetti! The library is written in TypeScript and compiled into…

how-to-create-popup-in-html-with-css

How To Create A Popup in HTML with CSS

How to create popup in html with css – Popup without JavaScript is an elegant pop-up panel component with an animated scale, written in CSS. Have you…

Leave a Reply

Your email address will not be published. Required fields are marked *