Ua kom zoo
Khaws koj cov phiaj xwm lean, teb, thiab tswj tau kom koj tuaj yeem xa cov kev paub zoo tshaj plaws thiab tsom mus rau cov haujlwm tseem ceeb dua.
Lean Sass imports
Thaum siv Sass hauv koj cov khoom vaj khoom tsev kav, xyuas kom koj ua kom zoo dua Bootstrap los ntawm tsuas yog @import
cov khoom koj xav tau. Koj qhov kev ua kom zoo tshaj plaws yuav zoo li los ntawm Layout & Components
ntu ntawm peb bootstrap.scss
.
// Configuration
@import "functions";
@import "variables";
@import "maps";
@import "mixins";
@import "utilities";
// Layout & components
@import "root";
@import "reboot";
@import "type";
@import "images";
@import "containers";
@import "grid";
@import "tables";
@import "forms";
@import "buttons";
@import "transitions";
@import "dropdown";
@import "button-group";
@import "nav";
@import "navbar";
@import "card";
@import "accordion";
@import "breadcrumb";
@import "pagination";
@import "badge";
@import "alert";
@import "progress";
@import "list-group";
@import "close";
@import "toasts";
@import "modal";
@import "tooltip";
@import "popover";
@import "carousel";
@import "spinners";
@import "offcanvas";
@import "placeholders";
// Helpers
@import "helpers";
// Utilities
@import "utilities/api";
Yog tias koj tsis siv cov khoom siv, tawm tswv yim tawm lossis tshem tawm tag nrho. Piv txwv li, yog tias koj tsis siv lub carousel, tshem tawm qhov kev ntshuam kom txuag tau qee cov ntaub ntawv loj hauv koj cov ntaub ntawv CSS. Nco ntsoov muaj qee qhov kev vam khom thoob plaws Sass ntshuam uas yuav ua rau nws nyuaj rau tshem tawm cov ntaub ntawv.
Yooj yim JavaScript
Bootstrap's JavaScript suav nrog txhua yam hauv peb cov ntaub ntawv tseem ceeb ( bootstrap.js
thiab bootstrap.min.js
), thiab txawm tias peb qhov kev vam khom thawj (Popper) nrog peb cov ntaub ntawv pob ( bootstrap.bundle.js
thiab bootstrap.bundle.min.js
). Thaum koj nyob nraum customizing ntawm Sass, nco ntsoov tshem tawm lwm yam JavaScript.
Piv txwv li, piv txwv tias koj tab tom siv koj tus kheej JavaScript bundler zoo li Webpack, Parcel, lossis Vite, koj tsuas yog import JavaScript koj npaj siv. Hauv qhov piv txwv hauv qab no, peb qhia yuav ua li cas thiaj li suav nrog peb cov qauv JavaScript:
// Import just what we need
// import 'bootstrap/js/dist/alert';
// import 'bootstrap/js/dist/button';
// import 'bootstrap/js/dist/carousel';
// import 'bootstrap/js/dist/collapse';
// import 'bootstrap/js/dist/dropdown';
import 'bootstrap/js/dist/modal';
// import 'bootstrap/js/dist/offcanvas';
// import 'bootstrap/js/dist/popover';
// import 'bootstrap/js/dist/scrollspy';
// import 'bootstrap/js/dist/tab';
// import 'bootstrap/js/dist/toast';
// import 'bootstrap/js/dist/tooltip';
Txoj kev no, koj tsis suav nrog JavaScript uas koj tsis xav siv rau cov khoom xws li cov nyees khawm, carousels, thiab cov lus qhia. Yog tias koj tab tom importing dropdowns, tooltips lossis popovers, nco ntsoov sau cov Popper nyob ntawm koj package.json
cov ntaub ntawv.
Default Exports
Cov ntaub ntawv bootstrap/js/dist
siv lub neej ntawd export , yog li yog tias koj xav siv ib qho ntawm lawv koj yuav tsum ua cov hauv qab no:
import Modal from 'bootstrap/js/dist/modal'
const modal = new Modal(document.getElementById('myModal'))
Autoprefixer .browserslistrc
Bootstrap nyob ntawm Autoprefixer kom tau txais qhov browser prefixes rau qee yam CSS khoom. Cov ntawv ua ntej tau hais los ntawm peb cov .browserslistrc
ntaub ntawv, pom nyob rau hauv lub hauv paus ntawm Bootstrap repo. Kev kho cov npe ntawm cov browsers no thiab rov ua dua Sass yuav cia li tshem tawm qee qhov CSS los ntawm koj cov CSS sau ua ke, yog tias muaj cov neeg muag khoom ua ntej tshwj xeeb rau qhov browser lossis version.
Tsis siv CSS
Pab xav nrog ntu no, thov xav qhib PR. Ua tsaug!
Thaum peb tsis muaj qhov piv txwv ua ntej rau kev siv PurgeCSS nrog Bootstrap, muaj qee cov lus pab thiab cov lus qhia uas cov zej zog tau sau. Nov yog qee qhov kev xaiv:
- Tsab ntawv xov xwm no tshwm sim thawj zaug https://medium.com/dwarves-foundation/remove-unused-css-styles-from-bootstrap-using-purgecss-88395a2c5772
- https://lukelowrey.com/automatically-removeunused-css-from-bootstrap-or-other-frameworks/
Thaum kawg, tsab xov xwm CSS Tricks ntawm CSS tsis siv qhia tau siv PurgeCSS thiab lwm yam cuab yeej zoo sib xws.
Minify thiab gzip
Thaum twg ua tau, nco ntsoov compress tag nrho cov cai koj ua haujlwm rau koj cov qhua. Yog tias koj siv Bootstrap dist cov ntaub ntawv, sim lo rau cov minified versions (qhia los ntawm cov .min.css
thiab .min.js
extensions). Yog tias koj tab tom tsim Bootstrap los ntawm qhov chaw nrog koj tus kheej tsim qhov system, nco ntsoov siv koj tus kheej minifiers rau HTML, CSS, thiab JS.
Tsis thaiv cov ntaub ntawv
Thaum minifying thiab siv compression yuav zoo li txaus, ua rau koj cov ntaub ntawv tsis-blocking sawv daws yuav kuj yog ib tug loj kauj ruam nyob rau hauv ua rau koj qhov chaw zoo-optimized thiab ceev txaus.
Yog tias koj tab tom siv Lighthouse plugin hauv Google Chrome, koj tuaj yeem ua yuam kev dhau FCP. Thawj Cov Ntsiab Lus Xim Xim ntsuas lub sijhawm los ntawm thaum nplooj ntawv pib thauj mus rau thaum twg ib feem ntawm nplooj ntawv cov ntsiab lus tau muab rau ntawm qhov screen.
Koj tuaj yeem txhim kho FCP los ntawm kev ncua JavaScript lossis CSS tsis tseem ceeb. Qhov ntawd txhais li cas? Yooj yim, JavaScript lossis stylesheets uas tsis tas yuav muaj nyob rau hauv thawj xim ntawm koj nplooj ntawv yuav tsum tau cim nrog async
lossis defer
cwj pwm.
Qhov no ua kom ntseeg tau tias cov peev txheej tsis tseem ceeb tau thauj khoom tom qab thiab tsis thaiv cov xim thawj zaug. Ntawm qhov tod tes, cov peev txheej tseem ceeb tuaj yeem suav nrog hauv cov ntawv sau lossis cov qauv.
Yog tias koj xav paub ntau ntxiv txog qhov no, twb muaj ntau cov lus zoo txog nws:
Ib txwm siv HTTPS
Koj lub vev xaib yuav tsum tsuas yog muaj nyob hauv HTTPS kev sib txuas hauv kev tsim khoom. HTTPS txhim kho kev ruaj ntseg, kev ceev ntiag tug, thiab muaj nyob ntawm txhua qhov chaw, thiab tsis muaj qhov zoo li lub vev xaib tsis muaj teeb meem . Cov kauj ruam los teeb tsa koj lub vev xaib kom tau txais kev pabcuam tshwj xeeb tshaj HTTPS sib txawv nyob ntawm koj qhov chaw tsim khoom thiab lub vev xaib hosting, thiab yog li dhau ntawm cov ntaub ntawv no.
Cov chaw ua haujlwm dhau HTTPS yuav tsum nkag mus rau txhua daim ntawv teev npe, ntawv sau, thiab lwm yam khoom muaj nqis ntawm HTTPS kev sib txuas. Txwv tsis pub, koj yuav xa cov neeg siv sib xyaw cov ntsiab lus nquag , ua rau muaj qhov tsis zoo uas lub xaib tuaj yeem cuam tshuam los ntawm kev hloov pauv kev vam khom. Qhov no tuaj yeem ua rau muaj teeb meem kev nyab xeeb thiab cov lus ceeb toom hauv browser tshwm rau cov neeg siv. Txawm hais tias koj tau txais Bootstrap los ntawm CDN lossis ua haujlwm rau koj tus kheej, xyuas kom meej tias koj tsuas yog nkag mus rau nws dhau HTTPS kev sib txuas.