u
This commit is contained in:
25
cache_urls.js
Normal file
25
cache_urls.js
Normal file
@@ -0,0 +1,25 @@
|
||||
async function fetch_urls (urls) {
|
||||
let seq = 1
|
||||
for (const url of urls) {
|
||||
const startTime = process.hrtime()
|
||||
try {
|
||||
const res = await fetch(url)
|
||||
const { status } = res
|
||||
const sizeDownload = res.headers.get('content-length') || 0
|
||||
const urlEffective = res.url
|
||||
|
||||
await res.text() // Consume the response body
|
||||
|
||||
const [seconds, nanoseconds] = process.hrtime(startTime)
|
||||
const timeTotal = seconds + nanoseconds / 1e9
|
||||
|
||||
console.log(`${seq++}/${urls.length} | ${status} | ${timeTotal.toFixed(3)} s | ${sizeDownload} bytes | ${urlEffective}`)
|
||||
} catch (e) {
|
||||
console.error(`Error fetching ${url}: ${e.message}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// example: fetch_urls(['https://u.cn.agidin.com/uni_modules/uni-pay/static/wxpay.png', 'https://u.cn.agidin.com/static/js/pages-user-resource.4a81c0a7.js'])
|
||||
|
||||
module.exports = fetch_urls
|
||||
Reference in New Issue
Block a user