1657880470
讓我們談談可用於測試網頁的最有用的技術 SEO 性能工具之一。它是自動化的,可以衡量性能、可訪問性和 SEO。更重要的是,它是開源的並且可以免費使用——並且可以用來測試漸進式 Web 應用程序,這是我想在本文中重點介紹的內容。讓我們一起瀏覽 Lighthouse 評分成功清單。但首先,一些信息:
Web 應用程序的 SEO 性能成為過去幾年最熱門的話題之一。作為開發人員,我們經常忘記它,直到為時已晚。這通常是由於嚴格的期限、缺乏知識或只是懶惰造成的。
今天,性能不僅僅是渲染應用程序所需的時間。糟糕的性能會導致糟糕的用戶體驗和更糟糕的 SEO 定位——不良結果的多米諾骨牌效應會損害你的應用程序。
您是否知道自 2010 年以來 Google 一直在關注網絡速度的排名?
您知道應用程序性能對用戶體驗甚至收入的巨大影響嗎?以下是谷歌研究“對移動速度的需求”的一些事實:
但別擔心,我準備了一份清單,可以幫助您提高應用程序的整體速度,同時改善用戶體驗、搜索引擎優化和收入。因為 Lighthouse 是由 Google 製造的,所以它使用相同的性能指標,並有助於以清晰直觀的方式改進您的漸進式 Web 應用程序。
讓我們開始提高您的 Lighthouse 性能得分。在我們繼續具體的提示和技巧之前,讓我們首先了解 Lighthouse 如何理解和計算性能分數。
Lighthouse的性能部分基於6 Web Vitals 測量頁面速度。
Web Vitals 是 Google 的一項舉措,旨在為質量信號提供統一指導,這些信號對於在網絡上提供出色的用戶體驗至關重要。
讓我們總結一下它們:
我們的應用程序包含 20 個任務:
TBT只關心 60 毫秒的任務(更準確地說,是 50 毫秒閾值與值本身之間的差異)。所以我們的最終結果將是:
數量 x(價值 - 閾值)= 結果
10 x (60ms – 50ms) = 100ms
有了這些知識,我們終於可以繼續“修復”我們的應用程序 Lighthouse 分數了!
為什麼字體會影響你的燈塔分數?這是因為它們的使用方式不僅會影響頁面速度(不同的字體有不同的大小,而且我們不僅僅指它們看起來有多大!)而且會對查看者如何查看您的頁面產生深遠影響正確加載。以下是一些需要注意的事項:
字體子集——一些字體有更小的變體,稱為“子集”。它們包含更少的字形,這進一步減小了文件的大小。例如,某些字體具有僅包含拉丁字母和字符的“拉丁”子集。
假設我們想使用字體的所有變體(在這個例子中是 9 個文件)。我們將之前的結果乘以 9,並將其大小與單個可變字體文件進行比較。
腳本也會影響您的性能——尤其是當它們在不需要的地方出現瓶頸或占用寶貴的加載時間時。使他們更容易表現的最佳方法是:
標記管理器——考慮將第三方腳本的加載委託給標記管理器,您可以更好地控制腳本加載的順序和腳本的數量。
您可以查看比較這兩種方法的這篇文章。此外,`Next.js` 已經內置了大量的 CSS 優化,比如類名和样式縮小、sass 支持、配置的 postcss,所以它是我們的一種方式。
字體顯示——為了避免 FOUT(無樣式文本的閃爍)或看到空白屏幕,您應該始終通過使用字體上的font-display屬性來控製字體的加載。
分析捆綁包可以很好地發現我們的塊的數量和大小。我們通常可以從這樣做的工具中學到很多東西。
module.exports = {
webpack(config, { isServer }) {
if (!isServer) {
config.optimization.splitChunks.cacheGroups = {
...config.optimization.splitChunks.cacheGroups,
'@sentry': {
test: /[\\/]node_modules[\\/](@sentry)[\\/]/,
name: '@sentry',
priority: 10,
reuseExistingChunk: false,
},
};
}
return config;
},
};
這樣,@sentry包將被分割成它自己的小塊。此外,我們可以控制模塊的優先級。
刪除重複的模塊——有時在 monorepo 架構中工作時,我們可能會得到多次捆綁的包。同樣,webpack config 帶有一個可以合併我們重複的塊的屬性。它看起來像這樣:
module.exports = {
optimization: {
mergeDuplicateChunks: true,
},
};
CLS 成為 2021 年的排名因素,所以它是相當新的。它代表 Cumulative Layout Shift,是衡量用戶體驗溫度的指標。
每當可見元素將其位置從一個渲染幀更改為下一幀時,就會發生佈局轉換。
為動態內容保留空間——為了防止任何意外的佈局變化,我們應該始終為尚未渲染的內容保留空間。
有很多很棒的方法,比如骨架加載,它模仿給定組件的一般外觀,包括它的寬度和高度。這樣,我們將保留確切的空間,從而消除 CLS。
但有時,我們不必使用任何花哨的東西。我們可以只插入一個空的佔位符框,這將確保用戶沒有不愉快的變化。
圖像可能是最臭名昭著的頁面速度惡棍,這個問題現在和 1999 年一樣真實。除了我們有更多的技巧來解決這個問題並提高你的整體性能得分。開始了:
Next/image –手動完成上述所有點可能既耗時又存在問題。幸運的是,有一些圖書館可以為我們處理它。其中之一是Next/Image組件,它將通過轉換為 webp、調整大小、延遲加載和預加載 API 為我們優化圖像。
有時,在 SEO 性能方面,JavaScript 可能會成為反派。為了提高應用程序的燈塔分數,我們可以避免一些常見錯誤:
// Exporting from barrel file
export Button from "ui/Button";
export Text from "ui/Text";
export Select from "ui/Select";
// Importing in component
import { Button, Select, Text } from "ui";
我們想直接從組件路徑導入:
// Importing in component
import Button from "ui/Button";
import Text from "ui/Text";
import Select from "ui/Select";
如果我們已經達到了讓我們滿意的性能水平,那麼隨著時間的推移將其保持在同一水平會很好。我們還不能稱之為星期五!有一些工具可以幫助我們做到這一點:
Lighthouse 或 WebPageTest 之類的工具有時會產生誤導,因為它們總是在穩定的互聯網連接、最新版本的 Chrome 等下工作……而對於我們的最終用戶而言,情況並非總是如此。通常,用戶在給定頁面上的表現可能比 Lighthouse 建議的要差得多。
個人推薦Sentry 的性能測量工具。它非常容易設置,並且會提供大量關於用戶設備、連接、位置等的信息,這可能有助於我們解決邊緣情況問題。
Web App 的性能不是我們可以修復一次就忘記的。它更像是一個隨著應用程序的增長而不斷檢查、分析和改進應用程序的過程。幸運的是,我們可以而且應該盡可能地自動化這個過程,讓我們的生活更輕鬆。
正確設置的工作流程可以防止我們推送會破壞我們的應用程序性能的代碼,在實施過程中發現錯誤,甚至指出我們應該關注的痛點。
鏈接:https ://tsh.io/blog/how-to-keep-your-lighthouse-score-high-in-next-js-applications-a-checklist/
#nextjs #javascript #lighthouse
1632537859
Not babashka. Node.js babashka!?
Ad-hoc CLJS scripting on Node.js.
Experimental. Please report issues here.
Nbb's main goal is to make it easy to get started with ad hoc CLJS scripting on Node.js.
Additional goals and features are:
Nbb requires Node.js v12 or newer.
CLJS code is evaluated through SCI, the same interpreter that powers babashka. Because SCI works with advanced compilation, the bundle size, especially when combined with other dependencies, is smaller than what you get with self-hosted CLJS. That makes startup faster. The trade-off is that execution is less performant and that only a subset of CLJS is available (e.g. no deftype, yet).
Install nbb
from NPM:
$ npm install nbb -g
Omit -g
for a local install.
Try out an expression:
$ nbb -e '(+ 1 2 3)'
6
And then install some other NPM libraries to use in the script. E.g.:
$ npm install csv-parse shelljs zx
Create a script which uses the NPM libraries:
(ns script
(:require ["csv-parse/lib/sync$default" :as csv-parse]
["fs" :as fs]
["path" :as path]
["shelljs$default" :as sh]
["term-size$default" :as term-size]
["zx$default" :as zx]
["zx$fs" :as zxfs]
[nbb.core :refer [*file*]]))
(prn (path/resolve "."))
(prn (term-size))
(println (count (str (fs/readFileSync *file*))))
(prn (sh/ls "."))
(prn (csv-parse "foo,bar"))
(prn (zxfs/existsSync *file*))
(zx/$ #js ["ls"])
Call the script:
$ nbb script.cljs
"/private/tmp/test-script"
#js {:columns 216, :rows 47}
510
#js ["node_modules" "package-lock.json" "package.json" "script.cljs"]
#js [#js ["foo" "bar"]]
true
$ ls
node_modules
package-lock.json
package.json
script.cljs
Nbb has first class support for macros: you can define them right inside your .cljs
file, like you are used to from JVM Clojure. Consider the plet
macro to make working with promises more palatable:
(defmacro plet
[bindings & body]
(let [binding-pairs (reverse (partition 2 bindings))
body (cons 'do body)]
(reduce (fn [body [sym expr]]
(let [expr (list '.resolve 'js/Promise expr)]
(list '.then expr (list 'clojure.core/fn (vector sym)
body))))
body
binding-pairs)))
Using this macro we can look async code more like sync code. Consider this puppeteer example:
(-> (.launch puppeteer)
(.then (fn [browser]
(-> (.newPage browser)
(.then (fn [page]
(-> (.goto page "https://clojure.org")
(.then #(.screenshot page #js{:path "screenshot.png"}))
(.catch #(js/console.log %))
(.then #(.close browser)))))))))
Using plet
this becomes:
(plet [browser (.launch puppeteer)
page (.newPage browser)
_ (.goto page "https://clojure.org")
_ (-> (.screenshot page #js{:path "screenshot.png"})
(.catch #(js/console.log %)))]
(.close browser))
See the puppeteer example for the full code.
Since v0.0.36, nbb includes promesa which is a library to deal with promises. The above plet
macro is similar to promesa.core/let
.
$ time nbb -e '(+ 1 2 3)'
6
nbb -e '(+ 1 2 3)' 0.17s user 0.02s system 109% cpu 0.168 total
The baseline startup time for a script is about 170ms seconds on my laptop. When invoked via npx
this adds another 300ms or so, so for faster startup, either use a globally installed nbb
or use $(npm bin)/nbb script.cljs
to bypass npx
.
Nbb does not depend on any NPM dependencies. All NPM libraries loaded by a script are resolved relative to that script. When using the Reagent module, React is resolved in the same way as any other NPM library.
To load .cljs
files from local paths or dependencies, you can use the --classpath
argument. The current dir is added to the classpath automatically. So if there is a file foo/bar.cljs
relative to your current dir, then you can load it via (:require [foo.bar :as fb])
. Note that nbb
uses the same naming conventions for namespaces and directories as other Clojure tools: foo-bar
in the namespace name becomes foo_bar
in the directory name.
To load dependencies from the Clojure ecosystem, you can use the Clojure CLI or babashka to download them and produce a classpath:
$ classpath="$(clojure -A:nbb -Spath -Sdeps '{:aliases {:nbb {:replace-deps {com.github.seancorfield/honeysql {:git/tag "v2.0.0-rc5" :git/sha "01c3a55"}}}}}')"
and then feed it to the --classpath
argument:
$ nbb --classpath "$classpath" -e "(require '[honey.sql :as sql]) (sql/format {:select :foo :from :bar :where [:= :baz 2]})"
["SELECT foo FROM bar WHERE baz = ?" 2]
Currently nbb
only reads from directories, not jar files, so you are encouraged to use git libs. Support for .jar
files will be added later.
The name of the file that is currently being executed is available via nbb.core/*file*
or on the metadata of vars:
(ns foo
(:require [nbb.core :refer [*file*]]))
(prn *file*) ;; "/private/tmp/foo.cljs"
(defn f [])
(prn (:file (meta #'f))) ;; "/private/tmp/foo.cljs"
Nbb includes reagent.core
which will be lazily loaded when required. You can use this together with ink to create a TUI application:
$ npm install ink
ink-demo.cljs
:
(ns ink-demo
(:require ["ink" :refer [render Text]]
[reagent.core :as r]))
(defonce state (r/atom 0))
(doseq [n (range 1 11)]
(js/setTimeout #(swap! state inc) (* n 500)))
(defn hello []
[:> Text {:color "green"} "Hello, world! " @state])
(render (r/as-element [hello]))
Working with callbacks and promises can become tedious. Since nbb v0.0.36 the promesa.core
namespace is included with the let
and do!
macros. An example:
(ns prom
(:require [promesa.core :as p]))
(defn sleep [ms]
(js/Promise.
(fn [resolve _]
(js/setTimeout resolve ms))))
(defn do-stuff
[]
(p/do!
(println "Doing stuff which takes a while")
(sleep 1000)
1))
(p/let [a (do-stuff)
b (inc a)
c (do-stuff)
d (+ b c)]
(prn d))
$ nbb prom.cljs
Doing stuff which takes a while
Doing stuff which takes a while
3
Also see API docs.
Since nbb v0.0.75 applied-science/js-interop is available:
(ns example
(:require [applied-science.js-interop :as j]))
(def o (j/lit {:a 1 :b 2 :c {:d 1}}))
(prn (j/select-keys o [:a :b])) ;; #js {:a 1, :b 2}
(prn (j/get-in o [:c :d])) ;; 1
Most of this library is supported in nbb, except the following:
:syms
.-x
notation. In nbb, you must use keywords.See the example of what is currently supported.
See the examples directory for small examples.
Also check out these projects built with nbb:
See API documentation.
See this gist on how to convert an nbb script or project to shadow-cljs.
Prequisites:
To build:
bb release
Run bb tasks
for more project-related tasks.
Download Details:
Author: borkdude
Download Link: Download The Source Code
Official Website: https://github.com/borkdude/nbb
License: EPL-1.0
#node #javascript
1625674200
In this video, we are going to implement Google Analytics to our Next JS application. Tracking page views of an application is very important.
Google analytics will allow us to track analytics information.
Frontend: https://github.com/amitavroy/video-reviews
API: https://github.com/amitavdevzone/video-review-api
App link: https://video-reviews.vercel.app
You can find me on:
Twitter: https://twitter.com/amitavroy7
Discord: https://discord.gg/Em4nuvQk
#next js #js #react js #react #next #google analytics
1625751960
In this video, I wanted to touch upon the functionality of adding Chapters inside a Course. The idea was to not think much and start the development and pick up things as they come.
There are places where I get stuck and trying to find answers to it up doing what every developer does - Google and get help. I hope this will help you understand the flow and also how developers debug while doing development.
App url: https://video-reviews.vercel.app
Github code links below:
Next JS App: https://github.com/amitavroy/video-reviews
Laravel API: https://github.com/amitavdevzone/video-review-api
You can find me on:
Twitter: https://twitter.com/amitavroy7
Discord: https://discord.gg/Em4nuvQk
#next js #api #react next js #next #frontend #development
1599119110
Next js Tutorial For Beginners is the today’s topic. It is no secret that creating single-page applications can be immensely challenging these days. But with the help of some libraries, frameworks, and tools, it is effortless nowadays. React.js is the common frontend libraries among the Front-end developers. Its virtual dom theory makes React faster and gives us the better application performance. Now, one problem is that Single Page Applications are not at all SEO friendly because it is rendered on the Client side and not Server side . So when the Search Engine crawlers try to send a request, they cannot get our meta content or description and not even the main content. Search Engines do not care about how your app is architected or whatever ideology was used to adjust and fetch the right material. Their bots are not as smart as using your apps as a real user would. All they care about is that once they send their spiders to crawl and index your site, whatever the server provides on the first request is what gets indexed. In our case, all they get is our div tag with an id and bundled JS file, and we can not index our website correctly. So some how, we need a SSR to tackle this problem and in React js, Next.js is the perfect solution.
#js #react.js #next.js
1657880470
讓我們談談可用於測試網頁的最有用的技術 SEO 性能工具之一。它是自動化的,可以衡量性能、可訪問性和 SEO。更重要的是,它是開源的並且可以免費使用——並且可以用來測試漸進式 Web 應用程序,這是我想在本文中重點介紹的內容。讓我們一起瀏覽 Lighthouse 評分成功清單。但首先,一些信息:
Web 應用程序的 SEO 性能成為過去幾年最熱門的話題之一。作為開發人員,我們經常忘記它,直到為時已晚。這通常是由於嚴格的期限、缺乏知識或只是懶惰造成的。
今天,性能不僅僅是渲染應用程序所需的時間。糟糕的性能會導致糟糕的用戶體驗和更糟糕的 SEO 定位——不良結果的多米諾骨牌效應會損害你的應用程序。
您是否知道自 2010 年以來 Google 一直在關注網絡速度的排名?
您知道應用程序性能對用戶體驗甚至收入的巨大影響嗎?以下是谷歌研究“對移動速度的需求”的一些事實:
但別擔心,我準備了一份清單,可以幫助您提高應用程序的整體速度,同時改善用戶體驗、搜索引擎優化和收入。因為 Lighthouse 是由 Google 製造的,所以它使用相同的性能指標,並有助於以清晰直觀的方式改進您的漸進式 Web 應用程序。
讓我們開始提高您的 Lighthouse 性能得分。在我們繼續具體的提示和技巧之前,讓我們首先了解 Lighthouse 如何理解和計算性能分數。
Lighthouse的性能部分基於6 Web Vitals 測量頁面速度。
Web Vitals 是 Google 的一項舉措,旨在為質量信號提供統一指導,這些信號對於在網絡上提供出色的用戶體驗至關重要。
讓我們總結一下它們:
我們的應用程序包含 20 個任務:
TBT只關心 60 毫秒的任務(更準確地說,是 50 毫秒閾值與值本身之間的差異)。所以我們的最終結果將是:
數量 x(價值 - 閾值)= 結果
10 x (60ms – 50ms) = 100ms
有了這些知識,我們終於可以繼續“修復”我們的應用程序 Lighthouse 分數了!
為什麼字體會影響你的燈塔分數?這是因為它們的使用方式不僅會影響頁面速度(不同的字體有不同的大小,而且我們不僅僅指它們看起來有多大!)而且會對查看者如何查看您的頁面產生深遠影響正確加載。以下是一些需要注意的事項:
字體子集——一些字體有更小的變體,稱為“子集”。它們包含更少的字形,這進一步減小了文件的大小。例如,某些字體具有僅包含拉丁字母和字符的“拉丁”子集。
假設我們想使用字體的所有變體(在這個例子中是 9 個文件)。我們將之前的結果乘以 9,並將其大小與單個可變字體文件進行比較。
腳本也會影響您的性能——尤其是當它們在不需要的地方出現瓶頸或占用寶貴的加載時間時。使他們更容易表現的最佳方法是:
標記管理器——考慮將第三方腳本的加載委託給標記管理器,您可以更好地控制腳本加載的順序和腳本的數量。
您可以查看比較這兩種方法的這篇文章。此外,`Next.js` 已經內置了大量的 CSS 優化,比如類名和样式縮小、sass 支持、配置的 postcss,所以它是我們的一種方式。
字體顯示——為了避免 FOUT(無樣式文本的閃爍)或看到空白屏幕,您應該始終通過使用字體上的font-display屬性來控製字體的加載。
分析捆綁包可以很好地發現我們的塊的數量和大小。我們通常可以從這樣做的工具中學到很多東西。
module.exports = {
webpack(config, { isServer }) {
if (!isServer) {
config.optimization.splitChunks.cacheGroups = {
...config.optimization.splitChunks.cacheGroups,
'@sentry': {
test: /[\\/]node_modules[\\/](@sentry)[\\/]/,
name: '@sentry',
priority: 10,
reuseExistingChunk: false,
},
};
}
return config;
},
};
這樣,@sentry包將被分割成它自己的小塊。此外,我們可以控制模塊的優先級。
刪除重複的模塊——有時在 monorepo 架構中工作時,我們可能會得到多次捆綁的包。同樣,webpack config 帶有一個可以合併我們重複的塊的屬性。它看起來像這樣:
module.exports = {
optimization: {
mergeDuplicateChunks: true,
},
};
CLS 成為 2021 年的排名因素,所以它是相當新的。它代表 Cumulative Layout Shift,是衡量用戶體驗溫度的指標。
每當可見元素將其位置從一個渲染幀更改為下一幀時,就會發生佈局轉換。
為動態內容保留空間——為了防止任何意外的佈局變化,我們應該始終為尚未渲染的內容保留空間。
有很多很棒的方法,比如骨架加載,它模仿給定組件的一般外觀,包括它的寬度和高度。這樣,我們將保留確切的空間,從而消除 CLS。
但有時,我們不必使用任何花哨的東西。我們可以只插入一個空的佔位符框,這將確保用戶沒有不愉快的變化。
圖像可能是最臭名昭著的頁面速度惡棍,這個問題現在和 1999 年一樣真實。除了我們有更多的技巧來解決這個問題並提高你的整體性能得分。開始了:
Next/image –手動完成上述所有點可能既耗時又存在問題。幸運的是,有一些圖書館可以為我們處理它。其中之一是Next/Image組件,它將通過轉換為 webp、調整大小、延遲加載和預加載 API 為我們優化圖像。
有時,在 SEO 性能方面,JavaScript 可能會成為反派。為了提高應用程序的燈塔分數,我們可以避免一些常見錯誤:
// Exporting from barrel file
export Button from "ui/Button";
export Text from "ui/Text";
export Select from "ui/Select";
// Importing in component
import { Button, Select, Text } from "ui";
我們想直接從組件路徑導入:
// Importing in component
import Button from "ui/Button";
import Text from "ui/Text";
import Select from "ui/Select";
如果我們已經達到了讓我們滿意的性能水平,那麼隨著時間的推移將其保持在同一水平會很好。我們還不能稱之為星期五!有一些工具可以幫助我們做到這一點:
Lighthouse 或 WebPageTest 之類的工具有時會產生誤導,因為它們總是在穩定的互聯網連接、最新版本的 Chrome 等下工作……而對於我們的最終用戶而言,情況並非總是如此。通常,用戶在給定頁面上的表現可能比 Lighthouse 建議的要差得多。
個人推薦Sentry 的性能測量工具。它非常容易設置,並且會提供大量關於用戶設備、連接、位置等的信息,這可能有助於我們解決邊緣情況問題。
Web App 的性能不是我們可以修復一次就忘記的。它更像是一個隨著應用程序的增長而不斷檢查、分析和改進應用程序的過程。幸運的是,我們可以而且應該盡可能地自動化這個過程,讓我們的生活更輕鬆。
正確設置的工作流程可以防止我們推送會破壞我們的應用程序性能的代碼,在實施過程中發現錯誤,甚至指出我們應該關注的痛點。
鏈接:https ://tsh.io/blog/how-to-keep-your-lighthouse-score-high-in-next-js-applications-a-checklist/
#nextjs #javascript #lighthouse