search results:

    • Standard
    • React
    Pricing Learn Community
    • + D
    • Light
    • Dark
    • System
    logo TW Elements
    • Getting started
      • Quick start
      • Tutorials
      • Design system
      • Local installation
      • Optimization
      • Dark mode
      • Theming
      • Changelog
      • Migrating to v2
      • Internationalization guide
      • Class customization
      • Icons Integration
    • CommercialNew
      • Pricing
      • License
      • Installation
      • Git & repository
      • Premium Support
    • Integrations
      • Angular
      • ASP.NET
      • Django
      • Express
      • Laravel
      • Next
      • Nuxt
      • Qwik
      • React
      • Remix
      • Solid
      • Svelte
      • SvelteKit
      • Vue
    • Content & styles
      • Animations
      • Animations Extended
      • Colors
      • Dividers
      • Figures
      • Headings
      • Hover effects
      • Icons
      • Images
      • Mask
      • Shadows
      • Typography
    • Navigation
      • Breadcrumbs
      • Footer
      • Headers
      • Mega menu
      • Navbar
      • Offcanvas
      • Pagination
      • Pills
      • Scrollspy
      • Sidenav
      • Tabs
    • Components
      • Accordion
      • Alerts
      • Avatar
      • Badges
      • Button group
      • Buttons
      • Cards
      • Carousel
      • Chips
      • Collapse
      • Dropdown
      • Gallery
      • Jumbotron
      • Lightbox
      • Link
      • List group
      • Modal
      • Notifications
      • Paragraphs
      • Placeholders
      • Popconfirm
      • Popover
      • Progress
      • Rating
      • Scroll back to top button
      • Social buttons
      • Spinners
      • Stepper
      • Testimonials
      • Timeline
      • Toast
      • Tooltip
      • Video
      • Video carousel
    • Forms
      • Autocomplete
      • Checkbox
      • Datepicker
      • Datetimepicker
      • File input
      • Form templates
      • Input Group
      • Inputs
      • Login form
      • Multi range slider
      • Radio
      • Range
      • Registration form
      • Search
      • Select
      • Switch
      • Textarea
      • Timepicker
      • Validation
    • Data
      • Charts
      • Charts advanced
      • Datatables
      • Tables
    • Methods
      • Clipboard
      • Infinite scroll
      • Lazy loading
      • Loading management
      • Ripple
      • Scrollbar
      • Smooth scroll
      • Sticky
      • Touch
    • Design Blocks
      • Admin Charts
      • Admin Complex
      • Admin Forms
      • Admin Maps
      • Admin Navigation
      • Admin tables
      • Banners
      • Contact
      • Content
      • CTA
      • FAQ
      • Features
      • Headers
      • Hero / Intro sections
      • Logo clouds
      • Mega menu
      • News
      • Newsletter
      • Pricing
      • Projects
      • Stats
      • Stats admin
      • Team
      • Testimonials
    • Tools
      • Button generator
      • Card generator
      • Flexbox generator
      • Footer generator
      • Form builder
      • Grid generator
      • Icon generator
      • Instagram Filters generator
      • Logo generator
      • Table generator
      • Typography generator
    • Coming Soon
      • Angular
      • Builder
      • Templates
      • Vue
    • Resources
      • Playground
      • YouTube Channel
      • Private FB Group
      • Newsletter
      • UI Design course New
      • UI / UX tips

    Optimization


    This guide describes in detail how to use the individual modules of the TW elements package to improve project performance and reduce the size of imported files.


    CSS optimization

    Tailwind is optimized to create as little CSS as possible, so there is no need to do anything else other than configure tailwind.config.js file.

    You can also use PurgeCSS as it is great tool that analyzes content of your html/javascript files and reduces CSS by deleting unused selectors.

    If you are using PostCSS plugin, another possibility to further optimize your app is to add cssnano at the end of the postcss.config.js

    • terminal
            
                
        npm install -D cssnano
        
            
        
    • postcss.config.js
            
                
        module.exports = {
          plugins: {
            tailwindcss: {},
            autoprefixer: {},
            ...(process.env.NODE_ENV === 'production' ? { cssnano: {} } : {})
          }
        }
        
            
        

    JS optimization

    TW elements provides a ES format that allows, instead of importing the entire library, to choose only the modules that are used in the project. Thanks to this, we significantly reduce the amount of KB downloaded by the application. It can be reduced even several times!

    For Example: In a new vite application, importing and using only input component, the build weights close to 30 kB. Using the same code but importing the entire library, the build weights a little bit over 300 kB.

    The only thing you have to remember is to always init the component using initTWE method provided in tw-elements library otherwise the components may not work properly.

    How to use the ES format of the TW elements?

    Here's a short instruction for importing a single module on the example of a Select component:

    Step 1

    Create a new project with TW elements. If you need step by step tutorial on how to create a new vite app and connect it with TW Elements, go to the Getting Started Vite page

    • terminal
            
                
          mdb init tailwind-elements
          
            
        

    Step 2

    Install dependencies

    • terminal
            
                
          npm install
          
            
        

    Step 3

    Add code of the basic example.

    • index.html
            
                
          <div class="flex justify-center">
            <div class="mb-3 xl:w-96">
              <select data-twe-select-init>
                <option value="1">One</option>
                <option value="2">Two</option>
                <option value="3">Three</option>
                <option value="4">Four</option>
                <option value="5">Five</option>
                <option value="6">Six</option>
                <option value="7">Seven</option>
                <option value="8">Eight</option>
              </select>
            </div>
          </div>
          
            
        

    Step 4

    Import Select from modules instead of importing only tw-elements.

    Note: The Select component will not work without the initTWE method unless you are using the UMD format.
    • src/index.js
            
                
          import { Select, initTWE } from "tw-elements";
          initTWE({ Select }, options);
          
            
        

    The options are documented in the TW Elements formats.

    Step 5

    Run the application

    • terminal
            
                
          npm start
          
            
        

    Step 6 *optional

    Run the build and compare the created JS weight. You can play around with other components and compare the builds.

    • terminal
            
                
          npm run build
          
            
        

    Tooling support

    VS Code + Tailwind CSS IntelliSense

    TW elements is registered as a plugin inside tailwind.config.js. That allows for our custom css classes to be picked up by the Tailwind CSS IntelliSense. If the IntelliSense is not showing our classes check whether the content inside tailwind.config.js is defined properly. We encourage to use it as it makes the live of a developer much easier.

    • CSS optimization
    • JS optimization
    • Tooling support
    Get useful tips & free resources directly to your inbox along with exclusive subscriber-only content.
    Join our mailing list now
    © 2024 Copyright: MDBootstrap.com

    Access restricted

    To view this section you must have an active PRO account

    Log in to your account or purchase an TWE subscription if you don't have one.

    Buy TWE PRO