How to set up how many minutes it takes to finish reading the blog page?

want to add the function of "it takes minutes to finish reading" to your blog. Does any boss know how to achieve this?
and this "~ times of reading". This has been introduced in the blog before, but I feel that the number of times of reading is not accurate. How can I accurately calculate the number of times of reading?

May.22,2021

it takes ~ minutes to finish reading

the total number of words in the article / how many words the average person can read per minute.
this must be a rough estimate.

~ read

most of the time, it is not necessary to be accurate, just rough statistics, of course, you have to be accurate statistics.
the rules for statistics of reading times may be different for each website
some websites add 1 to the number of page readings of articles once they are opened;
some sites are sites where a user opens the site for reading many times within a period of time, but the amount of reading only adds 1; there are many rules for
, depending on what rules are adopted in your project.
rough statistics or accurate statistics are generally implemented in the cache. The amount of reading is first placed in the cache, and then in the db that refreshes the amount of reading in the cache.
when will the amount of reading be brushed to db??
there are many solutions:
for example, when the reading volume of an article exceeds a specified threshold, it is refreshed in the db.
such as using scheduled tasks, and so on.

how long will it take to read the js implementation?
html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script class="jquery library" src="/js/sandbox/jquery/jquery-1.8.2.min.js" type="text/javascript"></script>
    <title>xxx</title>
  </head>
<body>
    <div id="content">
               

    </div> 
  </body>
</html>

js:

$(function(){
      var readLengthPerMinute = 400;//300-500400
        var textLength = $('-sharpcontent').text().length;//
       
      var readTime;
    if(textLength <= readLengthPerMinute){
          readTime = 1;
    }else{
        readTime =Math.round(textLength /readLengthPerMinute ); 
    }
       
    alert(":"+readTime+"");
});

Menu