# Sw Habitation > Sw Habitation ## Pages ### Stories - swhabitation.com URL: https://swhabitation.com/stories Updated: 2025-02-10T05:28:54.000Z Discover the journey of web development through our story page. Gain insights and inspiration from my experiences in the world of coding and design. ### Let's Talk - swhabitation.com URL: https://swhabitation.com/contact Updated: 2025-02-10T05:30:20.000Z Unleash the potential of your brand with transformative experiences. Join us at swhabitation.com and let's talk. ### Resources - swhabitation.com URL: https://swhabitation.com/resources Updated: 2025-02-10T05:28:30.000Z swhabitation.com offers a collection of informative resources, keeping you up to date with the ever-evolving world of web development. ### Privacy Policy - swhabitation.com URL: https://swhabitation.com/privacy-policy Updated: 2025-02-10T05:30:59.000Z Safeguard your online privacy with swhabitation.com's comprehensive privacy policy, designed to keep your personal information secure. ### Share Your Content - swhabitation.com URL: https://swhabitation.com/share-content Updated: 2025-02-10T05:31:29.000Z swhabitation.com - Stay up-to-date with the ever-evolving world of technology and web development through SWHabitation, your go-to resource for all things tech. ### Submit Link - swhabitation.com URL: https://swhabitation.com/submit-link Updated: 2025-02-10T05:20:38.000Z swhabitation.com - Stay up-to-date with the ever-evolving world of technology and web development through SWHabitation, your go-to resource for all things tech. ### Blogs - swhabitation.com URL: https://swhabitation.com/blogs Updated: 2025-02-10T05:27:04.000Z swhabitation.com offers a collection of informative blogs, keeping you up to date with the ever-evolving world of web development. ### Category - swhabitation.com URL: https://swhabitation.com/categories Updated: 2025-02-10T05:27:52.000Z Explore a wide range of topics on our blog website's category page. Stay informed and entertained with our diverse content selection. ### Comparison - swhabitation.com URL: https://swhabitation.com/comparison Updated: 2025-02-10T05:23:27.000Z swhabitation.com - Stay up-to-date with the ever-evolving world of technology and web development through SWHabitation, your go-to resource for all things tech. ### Media Kit - swhabitation.com URL: https://swhabitation.com/media-kit Updated: 2025-02-10T05:21:22.000Z swhabitation.com - Stay up-to-date with the ever-evolving world of technology and web development through SWHabitation, your go-to resource for all things tech. ## Blog ### Build AI-Powered SEO-Ready Sanity Sites with sanity-plugin-seo URL: https://swhabitation.com/blogs/build-ai-powered-seo-ready-sanity-sites-with-sanity-plugin-seo Published: 2026-07-18T00:00:00.000Z | Updated: 2026-07-21T10:02:44.000Z | Author: SW Habitation | Category: Sanity Sanity Studio is one of the best content editing experiences available but out of the box, SEO is entirely your responsibility. No meta title field, no description limit, no social preview, no score to tell editors whether a page is ready to rank. Every team handles it differently and none of the approaches scale. sanity-plugin-seo fixes that. One install adds a full SEO panel to every document in your Studio live scoring, keyword analysis, social previews, AI-generated meta, structured data, hreflang, GEO readiness for AI search engines, and more. This guide covers every feature so you know exactly what you are getting and how to configure it. Installation Works with Sanity v3, v4, and v5. Then add it to your sanity.config.ts: Reload the Studio. Every document type now has an SEO tab. Live SEO Score A real-time score ring (0–100) sits at the top of the SEO panel and updates as editors type no save required. The score reflects the overall readiness of the page for search engines based on everything the plugin can inspect at that moment. What moves the score: Meta title: present, 10–60 characters, contains focus keyword Meta description: present, 100–160 characters, contains focus keyword Focus keyword density in body content (1–3% is ideal) Open Graph image is set Canonical URL is filled in Editors see a color-coded ring: red is poor, amber is improving, green is ready. Beneath it, each contributing factor is listed so editors know exactly what to fix not just that something is wrong. Focus Keyword The focus keyword field drives keyword analysis across every other field. Once set, the plugin checks whether the keyword appears in the meta title, meta description, and body content and at what density. A keyword that appears in the title but not in the body, or appears 12 times and is flagged as stuffed, all shows up in the score breakdown. This works with the bodyField or bodyFields config you set at plugin initialization. The plugin extracts plain text from your Portable Text body and runs density analysis against it. Meta Title and Description Both fields have live character counters with color-coded feedback. Title turns green at 40–60 characters, description at 100–160. Editors see the current count and the ideal range without leaving the field. If AI generation is configured, a generate button sits next to each field. The meta title and description you set here are separate from the document title. This lets you write a longer H1 for the page while keeping the meta title tighter for search snippets. Open Graph — Live Social Preview The Open Graph section gives editors a live preview of how the page will look when shared on Facebook, LinkedIn, and other platforms that read OG tags. Upload an image, set the OG title and description, and the preview card updates in real time next to the fields. Fields available under Open Graph: OG Title — can differ from meta title for social context OG Description — separate from meta description OG Image — uploaded directly in Studio, recommended 1200×630 OG Type — article, website, etc. The preview renders at the right aspect ratio so what editors see in Studio matches what actually appears on social media. Twitter / X Card — Live Preview Separate from Open Graph, the Twitter Card section lets you set a card type (summary or summary_large_image), Twitter-specific title, description, and image. A live preview renders the card exactly as it appears in a tweet or link share on X. If you leave Twitter fields blank, most platforms fall back to OG tags — but having dedicated Twitter fields gives you per-platform control without any extra code. JSON-LD Structured Data — Automatic Structured data (JSON-LD / Schema.org) is what Google uses to generate rich results review stars, FAQ blocks, breadcrumbs, article metadata in search. It is notoriously painful to write manually and even more painful to keep accurate. sanity-plugin-seo generates it automatically. Based on the document type and the SEO fields the editor has filled in, the plugin produces the correct Schema.org JSON-LD: Blog posts and articles → Article schema with author, datePublished, dateModified Generic pages → WebPage schema with name, description, URL Organization data pulled from site settings if configured No editor action required it is on the GEO checklist as a passing item the moment the plugin is installed. Your frontend just reads the seoMetaFields.jsonLd field and injects it as a script tag. Canonical URL The canonical URL field lets editors specify the preferred version of a URL important when the same content is accessible at multiple paths (pagination, filters, query strings). A missing canonical on pages with URL variants causes Google to split ranking signals across duplicates. Set the canonical once in Studio, read it in your frontend, and output it as a standard link rel canonical tag. The live score rewards a filled canonical field. noindex and nofollow Controls Toggle noindex and nofollow per document directly from the SEO tab. noindex tells Google not to index the page at all useful for thank-you pages, preview links, staging content. nofollow tells Google not to pass link equity through outbound links on the page. These translate to the standard robots meta tag in your frontend: Hreflang — Multilingual and Multi-Region SEO If your site serves the same content in multiple languages or to region-specific audiences (en-US vs en-GB vs fr-FR), hreflang tags tell Google which URL to serve to which user. Getting these wrong or missing them entirely causes Google to pick the wrong language version, suppresses rankings in targeted regions, and can trigger duplicate content flags. The plugin gives you an hreflang manager in the SEO tab. Add entries with locale codes and corresponding URLs. The stored data maps directly to the HTML link tags your frontend outputs: AI Meta Generation Connect an AI provider and a Generate button appears next to the meta title and description fields. The plugin reads your document body content, sends it to the AI with instructions to write an SEO-optimised title and description at the correct character lengths, and fills the fields. Editors review and adjust they are not writing from scratch. Three providers are supported: Groq (Free Tier Available) Groq offers a generous free tier llama-3.3-70b-versatile is fast, capable, and costs nothing at typical content volumes. Sign up at console.groq.com, copy the API key, add three lines of config: OpenAI gpt-4o-mini costs roughly $2–5 per month at normal editorial volumes. Get a key from platform.openai.com: Anthropic claude-haiku-4-5 runs at roughly $1–3 per month. Get a key from console.anthropic.com: All API keys go in environment variables prefixed with SANITY_STUDIO_ so they are available in the browser Studio without being exposed in your frontend. bodyFields — AI That Reads Your Whole Page Most Sanity projects built with a page builder do not have a single body field. Content lives in sections arrays, nested content objects, column layouts sometimes three or four levels deep. The standard bodyField config only reads one field. bodyFields handles complex structures. Pass an array of paths: The plugin reads all of them, merges the text, and passes the combined content to the AI provider and to the keyword density analyser. This means the focus keyword analysis and AI generation both see the full page not just one fragment of it. For deeply nested structures you can also pass Sanity native path arrays: GEO Checklist — Optimising for AI Search Engines GEO stands for Generative Engine Optimization. It is the practice of structuring content so that AI-powered search engines ChatGPT, Perplexity, Google AI Overviews, Bing Copilot can parse, quote, and cite it. These tools do not just link to pages; they extract and reproduce specific passages. If your content is not structured correctly, you will not appear in AI-generated answers even when you rank well in traditional search. The plugin adds a 5-point GEO checklist that updates live in the SEO panel. Here is what each check does: 1. Structured Data Configured AI crawlers consume structured data to understand what type of content a page contains and who authored it. The plugin generates JSON-LD automatically this check passes the moment the plugin is installed with no action required from editors. 2. Description Is 100–160 Characters AI summarisation tools read meta descriptions as the primary summary signal. A description shorter than 100 characters gives them too little to work with. Longer than 160 and it gets truncated. The sweet spot is 120–150 enough to be a complete, quotable summary. This check enforces that range. 3. Open Graph Image Is Set When AI tools cite a page in a response, they often pull the OG image as a visual anchor. Pages without an OG image get cited less frequently and when they are, they appear as text-only, which reduces click-through. This check ensures every page has an image set. 4. Focus Keyword in Title and Description AI search engines rank pages for relevance the same way traditional search does by matching the user's query to page signals. A keyword in both the title and description is the clearest possible relevance signal. This check verifies both are present simultaneously. 5. Open Graph Fully Filled In Title, description, and image all set in the OG section. Incomplete OG data means AI crawlers fall back to guessing page context from body text which is less accurate and less likely to produce a usable citation. This check requires all three fields to be filled. Score 5/5 on the GEO checklist and your page is structured correctly for AI citation. Checks 1 and 5 are effectively automatic once structured data is enabled and OG is filled in which most editors do anyway for social sharing. The checklist surfaces the gaps they might otherwise miss. Reading SEO Data in Your Frontend The plugin stores everything in a seoMetaFields object on each document. Query it with GROQ and pass it into your framework's head management: Next.js App Router Astro Nuxt SvelteKit Sanity Version Compatibility sanity-plugin-seo works with Sanity v3, v4, and v5. The plugin API follows Sanity's plugin convention it is a standard definePlugin export with no monkey-patching, so upgrades between Sanity major versions do not break it. Install, configure once, update when you update Sanity. Where to Find It Package on npm. Full setup docs, AI config, and per-framework examples in the documentation. Feature overview and pricing (all free) on the plugin site. Source under MIT on GitHub. We use it across every project at SW Habitation. Conclusion ### Why CSS Transitions Slow Down Your Website and How to Fix It ? URL: https://swhabitation.com/blogs/why-css-transitions-slow-down-ui Published: 2025-09-01T00:00:00.000Z | Updated: 2025-09-01T09:07:13.000Z | Author: SW Habitation | Category: CSS We all love a smooth transition. A button that fades in gracefully, a card that slides up just right, or a modal that feels buttery when it appears it’s these little details that make an interface feel modern and polished. Sometimes CSS transitions don’t work the way we expect. Instead of being smooth, they stutter. Instead of improving UX, they make it worse. And instead of making our UI feel fast, they slow everything down. So what’s happening behind the scenes? Why do CSS transitions goes wrong? And more importantly how do we fix them? 1. Transitioning the Wrong Properties Not all CSS properties are created equal when it comes to transitions. Good properties to animate: opacity, transform like translate, scale, rotate. Bad properties to animate: width, height, top, left, margin. Wait why? Because properties like opacity and transform can be handled by the GPU, which is fast and efficient. But properties like width or top force the browser to recalculate layouts and repaint the screen super expensive operations. Quick Fix: Stick to transform and opacity whenever possible. If you need to resize something, try scaling instead of changing width/height directly. 2. Too Many Elements Transitioning at Once A single element fading in ? its smooth. A hundred elements all sliding and fading at the same time? The more elements the browser has to animate, the more work it has to do per frame. On slower devices, this often results in choppy motion. Quick Fix: Does every single element really need a transition? Sometimes just animating a parent container instead of each child achieves the same effect with less cost. 3. Long or Awkward Timing Functions Ever seen a transition that technically works but just feels “off”? That’s usually because of the easing curve. ease-in and ease-out can feel too slow in the wrong context. A poorly chosen cubic-bezier can make your UI feel unnatural. Long durations like 2s for a button hover make things feel sluggish. Quick Fix: For UI interactions, keep transitions short (150–300ms). Use ease or ease-in-out for natural feel. Reserve fancy cubic-bezier curves for special effects. 4. Mixing CSS with JavaScript Animations Sometimes developers mix CSS transitions with JavaScript-based animations (like setTimeout or requestAnimationFrame logic). If not handled carefully, this can cause jank stuttering due to the browser trying to sync two different animation systems. Quick Fix: Stick to one system for a specific animation. If it’s just a fade/slide, pure CSS is usually best. Use JS animations (e.g., with libraries like Framer Motion or GSAP) when you need complex choreography. 5. Forgetting About "Reduced Motion" Not all users love animations. For some, too much motion causes discomfort. If you don’t account for this, your transitions might break UX for a whole group of users. Quick Fix: Use the prefers-reduced-motion media query to offer a minimal or no-transition experience for those who opt out. Conclusion ### What is Blitz.js? Features, Pros, Cons, Installation & FAQs URL: https://swhabitation.com/blogs/what-is-blitzjs-features-pros-cons-installation-faqs Published: 2025-08-22T00:00:00.000Z | Updated: 2025-08-22T11:57:44.000Z | Author: SW Habitation | Category: Blitz JS If you’ve ever wished for a full-stack React framework that feels like Ruby on Rails but works in the modern JavaScript world, Blitz.js might be your new best friend. Think of it as Next.js on steroids – it keeps all the good parts of Next.js while adding powerful tools for building full-fledged apps faster. Let’s explore what Blitz.js is, what makes it special, how to install it step by step, and answer some beginner FAQs. What is Blitz.js? Blitz.js is a full-stack framework for React that’s built on top of Next.js. It’s designed to give developers everything they need in one package—frontend, backend, database, authentication, and even code scaffolding. If you’ve used Next.js, you already know the basics. But Blitz takes it further by removing a lot of the repetitive tasks and giving you a “batteries-included” experience. Key Features of Blitz.js Below are some features that make Blitz.js shine, Full-stack in one place: No need to separately set up frontend and backend projects. Zero-API Data Layer: You don’t have to manually write API routes. Your functions can be called directly from the frontend. Authentication out of the box: User signup, login, and sessions are already baked in. Code scaffolding: Quickly generate pages, forms, and CRUD with simple commands. Prisma integration: Works beautifully with Prisma ORM for database management. Next.js compatible: You still have SSR (Server-Side Rendering), SSG (Static Site Generation), and all the Next.js features you love. Advantages of Blitz.js Saves tons of setup time for full-stack apps. Great developer experience with code generation tools. Built-in auth and session management. Perfect for startups and MVPs (Minimum Viable Products). Uses popular tools like Next.js and Prisma. Disadvantages of Blitz.js Community is still small compared to Next.js. Might feel opinionated for some developers. Updates are not as frequent as bigger frameworks. Overkill if you just need a static site or simple frontend. Step-by-Step Installation Guide for Blitz.js Let’s go from scratch and install Blitz.js together. Step 1: Install Node.js Make sure you have Node.js v16 or later installed. You can check with: If not installed, download from nodejs.org. Step 2: Create a New Blitz.js App Run the following command in your terminal: It will ask you a few setup questions. Choose the options you prefer (default is fine for beginners). Step 3: Navigate to Your Project Step 4: Install Dependencies Blitz will install dependencies automatically, but if needed: Step 5: Run the Development Server Now visit http://localhost:3000 in your browser, and boom, your Blitz app is running. Step 6: Explore Authentication Blitz comes with user login and signup flows out of the box. You’ll already see the auth pages in your project. Conclusion ### What is Redwood.js? Features, Pros, Cons, Installation & FAQs URL: https://swhabitation.com/blogs/what-is-redwoodjs-features-pros-cons-installation-faqs Published: 2025-08-22T00:00:00.000Z | Updated: 2025-08-22T11:58:41.000Z | Author: SW Habitation | Category: Redwood JS Redwood.js is a full-stack JavaScript/TypeScript framework designed for building modern web applications with React on the frontend and GraphQL APIs on the backend. It’s heavily inspired by Ruby on Rails, aiming to bring the same productivity and developer happiness to the JavaScript ecosystem. If you’ve been looking for a framework that ties together frontend, backend, and database into one cohesive experience, Redwood.js might be the perfect choice. Key Features of Redwood.js Full-Stack Framework: Includes React (frontend), GraphQL API (backend), and Prisma (database). Cells Concept: Simplifies data fetching in React by managing loading, empty, and error states automatically. Prisma Integration: Built-in ORM support for relational databases like PostgreSQL, MySQL, and SQLite. Serverless-Ready: First-class support for serverless deployment on platforms like Netlify and Vercel. TypeScript Support: Works seamlessly with TypeScript for better type safety. Built-in Authentication: Provides out-of-the-box auth integrations (Auth0, Netlify Identity, etc.). Routing Made Simple: Easy file-based routing similar to Next.js. Pros of Redwood.js All-in-one: No need to manually connect React, GraphQL, and Prisma. Productivity Boost: Inspired by Rails, provides code generators and scaffolding. Great for Startups: Quickly go from prototype to production. Serverless-First: Perfect for JAMstack and modern deployments. Community-Driven: Backed by a growing community and contributors. Cons of Redwood.js Still evolving: Not as mature as Next.js or Meteor.js. Steep learning curve if you’re new to GraphQL or Prisma. Limited ecosystem compared to older frameworks. Opinionated structure (you must follow Redwood’s way of building apps). Installation: Step-by-Step Guide Here’s how you can set up a Redwood.js project from scratch, 1. Install Node.js Make sure you have Node.js (v16 or higher) installed. If not installed, download Node.js. 2. Install Yarn (Required) Redwood.js uses Yarn as its package manager. 3. Create a New Redwood App Use Yarn to create your Redwood project: This will scaffold a full-stack app with React + GraphQL + Prisma. 4. Navigate to Your App 5. Start the Development Server Your Redwood app will now be running at http://localhost:8910. Conclusion ### What is Meteor.js? Features, Pros, Cons, Installation & FAQs URL: https://swhabitation.com/blogs/what-is-meteorjs-features-pros-cons-installation-faqs Published: 2025-08-22T00:00:00.000Z | Updated: 2025-08-22T11:58:07.000Z | Author: SW Habitation | Category: Meteor JS If you are new to web development, you might have heard about Meteor.js. It’s one of the oldest and most popular JavaScript full-stack frameworks that makes it very easy to build apps quickly. Think of Meteor.js as a "ready-made toolbox" for building websites and mobile apps. You don’t need to spend hours connecting frontend, backend, and databases, Meteor gives you all these things in one package. What is Meteor.js? Meteor.js or just Meteor is an open-source full-stack JavaScript framework. It lets you build: Web apps Mobile apps (iOS/Android) Desktop apps Guess what is the best part? Meteor automatically updates the user interface (UI) when the database changes. For example, in a chat app, when one person sends a message, it shows instantly for others without refreshing the page. This "real-time magic" is what makes Meteor stand out. Key Features of Meteor.js Here are some features that make Meteor so special, Full-stack simplicity: Write frontend, backend, and database logic all in JavaScript. Real-time data updates: No need to refresh, changes are reflected instantly. MongoDB integration: Works perfectly with MongoDB right out of the box. Rapid prototyping: Build MVPs, demo apps, or startup projects super fast. Cordova support: Convert your web app into a mobile app (Android/iOS). Huge ecosystem: Access thousands of packages from Atmosphere and NPM. Cross-platform support: The same codebase can run on web and mobile. Advantages of Meteor.js Very beginner-friendly, easier than many modern frameworks. Real-time updates without writing extra code. One codebase for web + mobile apps. Huge collection of ready-to-use packages. Strong developer community with many tutorials and guides. Great for building startups, prototypes, and chat apps quickly. Cons of Meteor.js MongoDB dependency it works best with MongoDB, limited SQL support. Performance issues in very large or complex apps. Not as trendy/popular as frameworks like Next.js or Remix. Steeper scaling challenges when apps grow very big. Installation Guide for Meteor.js (Step-by-Step) Here’s how you can install Meteor.js on your computer: Step 1: Install Meteor For macOS/Linux: For Windows (using Chocolatey): Step 2: Create a new Meteor project Step 3: Move into the project folder Step 4: Run the app Now, open your browser and visit http://localhost:3000. Your first Meteor app is live. Conclusion ### What is Qwik.js? Features, Pros & Cons, Install Guide & FAQs URL: https://swhabitation.com/blogs/what-is-qwikjs-features-pros-cons-installation-faqs Published: 2025-08-20T00:00:00.000Z | Updated: 2025-08-22T11:56:45.000Z | Author: SW Habitation | Category: Qwik JS So you know how most JavaScript frameworks like React, Vue, Angular need to load big bundles before your site feels alive? Yup, that’s painful. Qwik.js comes with a crazy idea, what if the page is interactive instantly, without waiting for hydration or loading tons of JS? That’s Qwik. It’s built for speed. They call it resumable apps. In short, Qwik.js is a modern front-end framework that focuses on instant loading, lazy loading everything, and crazy fast performance. What is Qwik.js? Qwik.js is a next-gen front-end framework created by the team behind Builder.io. Its goal is to deliver the fastest possible websites by: Loading almost no JavaScript at first, Then resuming interactivity only when needed, And lazy-loading everything else on demand. Think of it as: React + magic, but faster. It’s not just another framework, it’s trying to solve the main problem with modern web, slow sites because of too much JS. Key Features of Qwik.js Developer Experience: JSX support (like React), and fast dev environment. Resumability: Instead of rehydrating like React/Vue, Qwik resumes from the server-rendered state. No JS boot-up. Lazy Loading Everything: Components, listeners, even code you don’t need right now – all lazy loaded. Built-in SSR & Edge Ready: Works with modern hosting like Vercel, Netlify, Cloudflare. Small Initial JS: Loads almost zero JS at first. SEO Friendly: Since it’s server-first, search engines love it. Why You Should Use Qwik.js? Instant loading websites: No hydration delay. Site feels interactive right away. Great for SEO: Because it sends real HTML from server, not empty divs. Super scalable: Even big apps can stay fast because everything is lazy. Modern Edge support: Works with edge functions and modern infra. Familiar syntax: Looks like React, so easy if you already know JSX. Downsides of Qwik.js Early adoption risk: Since it’s still evolving, APIs may change. New framework: Still young, ecosystem is not very big. Learning curve: Ideas like "resumability" are new, so takes time to understand. Smaller community: Not as many tutorials or libraries compared to React or Vue. Installation – How to Start with Qwik.js ? You can create a new Qwik app easily with their CLI. Then follow prompts to set up your app. Or if you want Qwik City (for routing + full stack features): Boom, you have a Qwik project running locally. When Qwik.js is a Perfect Choice You want future-ready tech, not legacy heavy frameworks. You want blazing fast websites where performance is #1. You’re tired of hydration problems in React/Vue apps. You care about SEO and Core Web Vitals. You’re building sites for global users (where internet may be slow). Why Not Just Use React or Vue? React and Vue are amazing, but they rely on hydration → meaning they re-download and re-run code in the browser to “wake up” the page. This can slow things down. Qwik skips hydration completely. It “resumes” from server state and then loads only what’s needed. That’s the magic. So yeah, if speed is your main goal → Qwik wins. Conclusion ### Alpine.js Introduction: Features, Pros & Cons, Install Guide URL: https://swhabitation.com/blogs/alpinejs-introduction-features-installation-guide Published: 2025-08-20T00:00:00.000Z | Updated: 2025-08-22T11:56:15.000Z | Author: SW Habitation | Category: Alpine.js JavaScript frameworks are scary sometimes right ? You hear names like React, Vue, Angular, Svelte and you think: “Do I really need to install 100 dependencies just to make a button toggle?” That’s where Alpine.js comes in. Think of Alpine like the “mini” version of Vue. It gives your HTML some superpowers without eating your brain cells. You can literally drop in a script tag and start using it. No complex setup, no bundlers, no headache. It’s perfect when you just need to sprinkle some interactivity into your website like dropdown menus, modals, tabs, accordions, form validation, counters all the small things. What Exactly is Alpine.js? Alpine.js is a lightweight JavaScript framework which is around 7KB gzipped, yup that small which makes your HTML reactive. Instead of writing long document.querySelector() scripts, you just write little attributes directly in your HTML like x-show, x-data, x-model etc. It feels almost like Vue, but way smaller and simpler. Example? Here’s a tiny counter app in Alpine: That’s it. No big setup. No imports. Just HTML with a sprinkle of Alpine. Key Features of Alpine.js Here are some of the cool things it can do: x-data → Store your state. x-model → Two-way data binding (like React’s useState). x-show / x-if → Conditional rendering. x-for → Loops (like rendering a list). x-transition → Add animations super easily. Magic helpers like $refs, $el, $dispatch, $watch. Basically, all the "good parts" of Vue/React but in mini size. Advantages of Alpine.js Very beginner friendly: You can learn it in a day. Easy to maintain for small components: Clean and declarative. Works well with server-rendered apps: If you use Laravel, Django, or PHP – Alpine is gold. Great for small projects: Don’t use react to create a simple dropdown. Super lightweight: Only ~7KB. Your users won’t even notice the extra load. No setup needed: Just add a script tag and done. Disadvantages of Alpine.js Not for big apps: No routing, no built-in state management. Small ecosystem: Not many third-party plugins compared to React or Vue. Messy if overused: Putting too much JS inside HTML can make it hard to read. Performance hit in very big DOM updates: Because it directly touches the DOM (no virtual DOM like React). So basically, Alpine is not trying to be React or Vue. It’s more like “jQuery’s modern replacement. How to install Alpine.js ? There are two ways: 1. The easy way using CDN : Just add this in your Done, Now you can start writing Alpine code in your HTML. 2. The modern way using npm: This is good if you’re working with modern bundlers or frameworks. When Alpine.js is a Perfect Choice You’re a beginner and want to learn how frameworks work in a fun way. You just need a quick prototype, no time for React or Vue setup. You’re making a static site but want dropdowns, modals, or tabs. You use Laravel / PHP / Django and need some JS sprinkles. You want to replace jQuery with something modern. Why Not Just Use Vanilla JS? Good question. Yes, you can do all of this with plain JavaScript. But, Alpine makes it short and sweet. You’ll write more code. You’ll repeat yourself again and again. Conclusion ### Why position: absolute Doesn’t Work Inside Flexbox ? URL: https://swhabitation.com/blogs/absolute-position-not-working-in-flexbox Published: 2025-08-08T00:00:00.000Z | Updated: 2025-08-11T04:43:23.000Z | Author: SW Habitation | Category: CSS Flexbox is amazing for arranging elements on a page. position: absolute is great for taking an element out of the normal flow and placing it exactly where you want. So naturally, combining them should be awesome right? Well… sometimes it is. Sometimes it completely breaks your layout, Yess. In this blog, we’ll cover why using position: absolute inside Flexbox can cause unexpected behavior and the right way to fix it. Why Does It Break? When you put an absolutely positioned element inside a flex container: The element is removed from the flex flow, meaning the flex container won’t consider it in its sizing or alignment. It will be positioned relative to the nearest positioned ancestor (the closest parent with position: relative, absolute, or fixed). Flex alignment properties (align-items, justify-content) won’t affect it. 1. It Ignores Flex Sizing If your flex item is position: absolute, Flexbox no longer controls its width or height. Fix: Use position: relative if you still want Flexbox sizing to apply, or manually set dimensions for the absolute item. 2. It Can Escape the Container If the flex parent doesn’t have position: relative, the absolute element may align to the body instead of your intended container. Fix: Always set the flex container to position: relative if you need absolute children to stay inside it. 3. Alignment Stops Working align-items: center won’t work on an absolute item. Fix: Manually center it using transforms: Example: Key Takeaways Absolute items are removed from Flexbox flow → Flex sizing & alignment won’t apply. Always set position: relative on the flex container. Manually position & size absolute elements. For responsive layouts, avoid absolute positioning unless necessary. Conclusion ### z-index Not Working? Fix CSS Stacking Issues Easily URL: https://swhabitation.com/blogs/fix-z-index-not-working-css Published: 2025-08-04T00:00:00.000Z | Updated: 2025-08-04T13:31:39.000Z | Author: SW Habitation | Category: CSS If you’re a beginner trying to build a popup, dropdown, modal, or tooltip and it's hiding behind something you've likely yelled at your screen: But I gave it z-index: 9999 then WHY isn’t it on top? Same here. I thought z-index was just about giving a higher number to an element to make it appear in front. But in practice? It felt like black magic. Things didn’t layer right, overlays disappeared, and sometimes… absolutely nothing worked. Turns out, it’s not the number. It’s the context. You’ve done it too: What is z-index? In the simplest way: z-index controls what comes on top and what stays behind. But there's a catch, z-index only works if your element is in the right stacking context. Let’s decode that word... What is Stacking Context? Imagine you’re placing stickers on transparent sheets. Some sheets are above others, and each sheet has stickers with their own order. In CSS, those transparent sheets are stacking contexts. If your element is inside a lower sheet, it’ll never appear on top, no matter the z-index. Common ways stacking contexts are created: Any element with position: relative, absolute, fixed, or sticky & z-index Using transform, filter, perspective, opacity < 1, etc. Even if you give something z-index: 99999, if it’s inside a stacking context that’s lower than another, it won't rise above. Real-Life Dev Mistake (aka What I Did) I had this: Still... the modal was hidden behind a navbar. The reason? The navbar was in another stacking context, one that had a higher position + z-index combo. Fix: Bring the Right Parent Up The solution isn’t just to give your element a higher z-index. You often need to check its parent container too. That’s the real culprit in 90% of cases. How to fix: Find the stacking context your element lives in Make sure that context itself can go on top Adjust the parent’s z-index accordingly Example: Or just take it out of other containers that limit its stacking. Common Situations Where z-index Breaks Quick Debug Checklist Is your element positioned (relative, absolute, fixed)? Is there a parent creating a stacking context? Are other elements using high z-index + position? Are you using transform, opacity, filter on parents? If yes => these might be making your life harder. Use browser dev tools => right-click => Inspect => check z-index and stacking context in Styles tab. One more, When you don’t give a z-index, it defaults to auto. And here’s the deal: auto means "I’ll stay in line with my stacking context." So your element might not get layered properly — even if you think it should. Be explicit. Don’t just trust the browser. Conclusion ### Why HD Images Look Blurry on Mobile and How to Fix It ? URL: https://swhabitation.com/blogs/why-hd-images-look-blurry-on-mobile Published: 2025-08-02T00:00:00.000Z | Updated: 2025-08-04T13:31:01.000Z | Author: SW Habitation | Category: CSS Your image is HD, but still looks bad on mobile? You’re not alone. You upload a 1920×1080 image which is clean, high-quality, looks great on your desktop. But when you open it on your iPhone or a good Android phone, The image looks blurry plus The text isn’t sharp plus The colors feel faded You double-check your file. It’s big in size, it’s in HD. So what’s wrong? Simple answer here, Today's phones use high-resolution (Retina) screens. They need images that are even sharper than basic HD. This guide explains why HD images often look bad on mobile, and how you can fix them easily using HTML, Tailwind CSS, Next.js, or Astro — with real examples and simple tips. Let’s get started. 1. Retina Screens Need 2x or 3x Image Sizes Modern phones don’t just show pixels instead they show 2x or even 3x the detail in the same space. That’s why a normal HD image can look blurry. So if your image is 300px wide, the screen is looking for 600–900px worth of detail. If you give it only 300px, it stretches and becomes blurry. How to Fix ? Use srcset to serve different versions based on screen density: Tailwind Tip: For logos or icons, use SVG whenever possible, it's always sharp: 2. You’re Scaling Up a Small Image in CSS Sometimes, the image file is too small, but you’re forcing it to fill a large area using CSS. That makes it jagged or blurry. Example: you upload a 400px image, but the layout stretches it to 1000px. Boom — blur! How to Fix ? Make sure your image is big enough for the space it fills. And use proper CSS: Also, check your layout and container sizes. 3. Compression Gone Wrong Yes, you should compress images. But too much compression can destroy quality. Common Issues: JPEGs look patchy or lose detail PNG edges look soft WebP looks weird if exported wrong How to Fix ? Use WebP or AVIF for modern image formats Don’t reduce quality below 80–85% Always preview before uploading 4. Missing width/height in Tag This is a small mistake that causes big problems. If you don’t set width and height, the browser guesses — and that can make images blurry or jumpy. This also improves Core Web Vitals (LCP score). 5. Not Using Framework Tools (Next.js / Astro) Using plain tags in frameworks like Next.js is a missed opportunity. These tools give you better control and built-in optimization. Next.js Example: Why this helps, Responsive image sizes Lazy loading Retina support CDN-based optimization Better page speed 6. Safari Rendering Issues (Especially on iPhones) Safari (especially iOS) is known for weird image behavior, Not scaling images properly Over-compressing in low-power mode Bugs with tag How to Fix ? Always use pixel-based width/height Use object-fit: cover Test your site on real iPhones, not just emulators Preload important images 7. Lazy Loading Isn’t Working Right Sometimes, lazy loading causes images to look blurry, especially when placeholders don’t swap correctly. How to Fix ? Use priority for above-the-fold images Only use blur placeholders for small images Check if IntersectionObserver is triggering properly AVIF vs WebP — Which One’s Better? WebP: Great support, sharp, good for all images AVIF: Newer, smaller size, but sometimes softer edges Suggestion: Use WebP for now (safe choice) Try AVIF if your app targets mostly Chrome/Android users Quick Recap Table Conclusion: ### Why Your CSS Grid Is Overflowing and How to Fix It ? URL: https://swhabitation.com/blogs/css-grid-overflow-causes-fixes Published: 2025-08-01T00:00:00.000Z | Updated: 2025-08-02T12:07:18.000Z | Author: SW Habitation | Category: CSS You’ve spent hours building a clean, responsive grid layout. Everything looks perfect in your browser. You deploy it and feel proud. Then QA or your client or even your own phone drops the bomb: Why’s the layout scrolling sideways? One box is out of place. It’s breaking on my screen. And just like that, you're deep in DevTools trying to figure out what went wrong with your beautiful CSS grid. Sound this things familiar right ? Yeah, it happens to literally every day. Let's get checked out what is the common reasons your CSS Grid is overflowing and how to fix ? 1. Content Inside Grid Is Too Damn Wide Ever put a long URL, image, or heading inside a grid item and it just... refuses to wrap? That’s prob it. What happens: Looks fine in your code or DevTools, Breaks only with real content. ✅ Try this: Oh using Tailwind? Easy: 2. You Used grid-template-columns: auto Yeah… auto seems innocent, but it literally tells the grid: please expand based on content size😬 ✅ Use fr units instead: 3. Images/Videos Are Not Constrained You drop in an and forget to set proper sizing. Next thing you know, it’s sticking out of the grid like it owns the place. ✅ Always set: Tailwind: 4. No Gap or Padding Between Items When there’s no gap in your grid, stuff just crashes into each other or bleeds outside the container. ✅ Use gap: Even small spacing can prevent layout chaos. 5. The Container Is the Real Villain You might’ve set width: 100vw on the container or ignored scrollbars. That tiny miscalculation? Causes layout overflow even if your grid is fine. ✅ Set this: Tailwind: ✅ Quick Debug Checklist Please check everything before blaming the grid. Any long words, URLs, or text with nowrap? Are images/videos wrapped properly with w-full and max-w-full? Still using auto instead of fr? Did you add box-sizing: border-box? Forgot min-w-0 inside a flex or grid child? Testing with lorem ipsum or real user data? Conclusion ### How to Fix Mobile Form Inputs Breaking Layout on Sites? URL: https://swhabitation.com/blogs/fix-mobile-form-inputs-breaking-layout Published: 2025-07-09T00:00:00.000Z | Updated: 2025-08-02T12:09:43.000Z | Author: SW Habitation | Category: CSS Are you getting tired of the OG things like "Mobile Form Inputs Wrecking Your Layout?" then you’re not alone friend. Have you ever built a form that looks perfect on desktop right…and even in the mobile emulator… Only to watch it fall apart the moment someone types on a real phone? Buttons vanish behind the keyboard The page jumps around unexpectedly Your carefully crafted layout turns into a mess Yes, mobile form confusion is real. And it’s especially painful on iOS and Safari. But Not to worry. In this guide, you’ll learn why this happens and how to fix it with ninja techniques. Let’s dive in and make your forms mobile-proof. 🤯 Why Forms Break Layout on Mobile ? 1. Virtual keyboards push the viewport up When a user focuses on an input, the mobile keyboard slides in right, but it doesn't just sit on top of the page. It often resizes the viewport or shifts the content upward. This can lead to weird scroll behavior or elements that vanish entirely. 2. position: fixed or absolute gets messed up Elements with position: fixed that you thought were anchored to the bottom? Surprise....they’re suddenly floating mid screen when the keyboard is open. That's because the browser recalculates positions relative to the new (shrunk) viewport. 3. 100vh isn’t real on iOS (again 😤) Do you know here iOS lies. When you use height: 100vh, Safari interprets that as the height of the full screen, not accounting for the browser UI or the keyboard. So when the keyboard appears, your full-screen modals, menus, or overlays can end up oversized and broken. 4. Android behaves differently from iOS What works on Android might totally fall apart on iOS and vice versa. Android might resize the layout, while iOS just overlays the keyboard, leading to inconsistent behavior. Yes, Testing on both is essential, and painful. 5. Inputs near the bottom get covered You tap a field near the bottom of the page and it hides behind the keyboard. Scrolls don’t always trigger automatically, so the user is left typing blindly. Some platforms just like iOS try to auto-scroll. Real Fixes & Dev Survival Tips 1. Use scrollIntoView() for Focused Fields Sometimes the page doesn’t scroll to the input, especially in modals. Also helpful for multi-step forms or chat UIs. 2. Don’t Use 100vh on Form Pages We’ll say it for the 100th time it lies. Use --vh or min-height: 100% and flex-grow layout structure instead: This allows inputs and content to shift smoothly without breaking layout. 3. Detect Virtual Keyboard Events (iOS & Android) You can hide footers or CTAs when input is focused: Then in CSS: Works across platforms and keeps inputs visible. 4. Avoid position: fixed for CTA Buttons in Forms Use position: sticky or place buttons inline within the form instead. If you must use fixed, toggle its visibility during input focus events. 5. Watch Out for autofocus on Mobile An input with autofocus on page load can: Trigger the keyboard instantly Shift layout upward Hide other content 🛑 Avoid autofocus unless it’s 100% needed especially on mobile. Tailwind Form UX Strategy Here’s a basic safe layout: Optional: Hide footer on focus with .keyboard-open. Conclusion ### What is Flutter? Key Features, Advantage and Disadvantage. URL: https://swhabitation.com/blogs/what-is-flutter-advantage-and-disadvantage Published: 2025-06-14T00:00:00.000Z | Updated: 2025-06-16T06:01:37.000Z | Author: SW Habitation | Category: Flutter So, If you've ever dreamed of building a beautiful, fast, and cross-platform app with a single codebase, then Flutter is perfectly your new best friend. Whether you're a beginner or a developer, Flutter has something magical for everyone here. Let's dive into what Flutter is, how it works, its pros and cons, and why Dart basically its programming language matters. What is Flutter? Flutter is an open-source UI toolkit developed by Google. It allows developers to create natively compiled applications for mobile, web, and desktop from a single codebase. Yup you heard it right, one codebase = multiple platforms. It’s known for its expressive UI, hot reload feature, and the ability to build stunning apps super quickly. It was first released in 2017, and since then, it has rapidly grown in popularity among developers worldwide. Flutter apps are built using the Dart programming language and rendered using Skia, a powerful 2D rendering engine. What is Dart (In Terms of Flutter)? Dart is the backbone of Flutter. Think of Flutter as the toolkit that gives you widgets and tools to build apps and Dart is the language that powers it all. It’s how you write the logic, UI, and even animations. If Flutter is the brush and canvas, Dart is the paint. Why Dart for Flutter? Ahead-of-Time (AOT) & Just-in-Time (JIT): JIT makes development faster (with hot reload), and AOT makes the final app fast and optimized. Fast Compilation: Dart compiles to native code (ARM or x64) which makes Flutter apps fast. Object-Oriented: Makes it easy to manage and reuse code using classes. Asynchronous Friendly: With async/await, you can easily handle network calls, I/O, etc. Clean Syntax: Dart feels like a mix of Java, JavaScript, and C#, so many developers pick it up quickly. A Simple Dart Example in Flutter This above simple app is 100% written in Dart and uses Flutter's widget system to build a UI. Everything from Text() to Scaffold() is part of Flutter’s widget tree, controlled by Dart. How to Get Started with Flutter Getting started with Flutter is easier than it sounds. Here's a quick steps, 1. Install Flutter SDK Go to flutter.dev Download the SDK for your OS (Windows, macOS, Linux) Add Flutter to your system path 2. Install Android Studio or Visual Studio Code VS Code is lightweight and fast Install Flutter and Dart plugins/extensions 3. Set Up an Emulator or Connect a Device Use Android Emulator or iOS Simulator Or connect your real device via USB and enable developer mode 4. Create Your First Project Yeah, You're running a real Flutter app already. Key Features of Flutter Material and Cupertino: Build Android and iOS style UIs using a unified API Single Codebase: Write once, run anywhere (Android, iOS, Web, Desktop) Hot Reload: Instantly see changes in your app without restarting High Performance: Compiles to native ARM code using Dart, resulting in smooth performance Customizable Widgets: Use pre-built widgets or build your own for a pixel-perfect UI Rich Ecosystem: Access thousands of packages for almost every functionality Advantages of Flutter Consistent UI Across Platforms Huge Library of Plugins and Packages Faster Development with Hot Reload Cross-Platform Support (Android, iOS, Web, Desktop) Strong Community and Support Backed by Google (which means active development and regular updates) Disadvantages of Flutter Learning Curve: If you’re not familiar with Dart, there's an initial learning bump Still Growing: Though popular, it's still maturing compared to native SDKs Web and Desktop Support: Improving, but still catching up to mobile stability Limited Access to Native APIs: Some advanced native functionalities may require writing platform-specific code App Size: Flutter apps can be larger in size compared to native apps Comparison Table Real-World Examples Using Flutter Reflectly: A mindfulness journal app with beautiful design Tencent, Nubank, Toyota: The list keeps growing Google Ads: Google’s own ad management app is built using Flutter BMW, Alibaba, eBay Motors: Big names adopting Flutter Conclusion ### Best SEO plugin for astro.js - Astro SEO Plugin. URL: https://swhabitation.com/blogs/best-astro-seo-plugin Published: 2025-05-07T00:00:00.000Z | Updated: 2025-05-22T06:47:30.000Z | Author: SW Habitation | Category: Astro In this blog, we’ll walk you through a beginner-friendly way to add SEO to your Astro project using a powerful tool called astro-seo-plugin. We’ll explain what Astro is, why SEO matters, and give you a copy-paste setup to make your website ready for Google, social media, and more. What is Astro? Astro is a fast and modern web framework that helps you build websites with minimal javaScript. It's great for blogs, portfolios, and content-heavy sites. Why developers love Astro: You can write components in your favorite framework Perfect for SEO and static sites It delivers lightning-fast page loads Supports React, Vue, Svelte, Solid, and more But even though Astro is SEO-friendly it still needs help with meta tags, Open Graph, Twitter Cards, and structured data, and that’s where astro-seo-plugin comes in. What is astro-seo-plugin? The astro-seo-plugin is a helpful plugin for adding all the important SEO meta tags to your Astro pages. Instead of writing a dozen tags by hand, you use a single component: . It handles things like: Page titles & descriptions Open Graph tags (for Facebook, LinkedIn) Twitter card tags JSON-LD structured data Robots settings (to tell Google what to do) Extra meta and link tags Installation & Setup Step 1: Install the Plugin Open your terminal and run, In your .astro layout or any page, import and use it like this below, Advantages of using astro-seo-plugin Works with Any Astro Page: Use it globally or per page as needed. Google-Friendly Structured Data: Helps Google understand your site better using JSON-LD. SEO Made Easy: Add all your SEO tags with one simple component. Social Media Ready: Your content looks great when shared on Twitter, Facebook, and LinkedIn. Saves Time: Forget manually writing meta tags for every page. Conclusion ### Capri.build: Fast Static Site Generator with Islands URL: https://swhabitation.com/blogs/capri-build-fast-static-site-generator-with-islands Published: 2025-03-10T00:00:00.000Z | Updated: 2025-03-10T16:15:57.000Z | Author: SW Habitation | Category: Static Site Generator If you’re very beginners to web development and looking for an easy way to build fast, lightweight websites, you might have come across Capri.build. But what exactly is the Capri term ? Capri is a static site generator (SSG) that lets you build websites using popular frontend frameworks like React, Vue, Svelte, Preact, or SolidJS—without sending unnecessary javascript to the browser. Unlike the traditional SSGs that we have worked with, Capri follows an "Islands Architecture". That means your site is static by default but allows selective interactivity only where needed. By using capri, you can build a static website as if it was a single page app. If you already know how to build an SPA in your choice of frameworks you know everything it takes. You can see which frameworks capri is supported by here. What is Capri? Capri is a modern static site generator that build static sites with interactive islands. Uses React, Vue, Svelte, Preact, or SolidJS -Its your choice Generates fully static pages - zero JavaScript by default Supports interactive components called islands without making the entire page dynamic Integrates with Vite for a smooth developer experience Works with headless CMSs for easy content management If you’ve used Next.js, Astro, or 11ty, Capri feels similar but forwards less JavaScript by default, that makes your site even faster. Why use Capri ? Blazing Fast: Capri doesn’t load unnecessary JavaScript, your website loads super quickly. Eco-Friendly: Less JavaScript === Lower energy consumption, making Capri a great choice for sustainable web development. Easy to Use: You can write components in React, Vue, Svelte, Preact, or SolidJS, so no need to learn a new framework. Efficient Interactivity: Instead of making the whole page dynamic, you only add JavaScript where it's needed. SEO-Friendly: The pages are fully static, search engines can easily index them, improving your Google ranking and make your webiste seo in good state. How to Install Capri ? A step-by-step guide 1. Install Capri Open your terminal and run below command, Replace my-project with your favourite project name. This sets up a new Capri project. 2. Choose Your Framework Capri supports multiple frameworks. You can select one during setup, like: or 3. Install Dependencies 4. Run the Development Server This starts a local server where you can preview your site. How Capri Uses "Islands Architecture" for Interactivity ? What is the "Islands" term? Most static site generators either, - Keep everything static means no interactivity or - Make everything dynamic (slow performance) Capri solves this problem by letting you selectively add interactivity only where you need it. These interactive sections are called "Islands" If you want a static site but need some interactivity, just name your component with .island. For example: components/ Header.tsx # Static component Counter.island.tsx # Interactive component Footer.tsx # Static component Here, only Counter.island.tsx will have javaScript, while the rest of the page remains pure HTML/CSS. Capri with Vite Capri works flowlessly with Vite. Just add this to your vite.config.ts, This ensures Capri integrates smoothly with Vite. Who should use capri? Absolute Beginners: If you're new to web development and want to build a fast site without much complexity. Eco-Conscious Developers: If you care about sustainable web development, Capri is a great choice. Bloggers & Content Creators: Capri is great for blogs, portfolios, and documentation sites because of its SEO benefits. Frontend Developers: If you love React, Vue, or Svelte and want a simpler alternative to Next.js. Conclusion ### How to Fix Hydration Errors in Next.js ? A Complete Guide URL: https://swhabitation.com/blogs/how-to-fix-hydration-errors-nextjs Published: 2025-03-08T00:00:00.000Z | Updated: 2025-03-10T05:34:21.000Z | Author: SW Habitation | Category: Next Js Have you ever seen this error in your Next.js app? Hydration failed because the server-rendered HTML did not match the client.... What is Hydration ? Hydration is the process where static HTML becomes interactive by adding javascript to it. When a web page is rendered on the server it loses its interactivity and event handles before getting to the client. Now react come into the picture. React adds the interactivity and event handlers that were lost when the HTML was server-side rendered. Lets understand in some simple terms, This is a hydration error, and it happens when the server renders one version of your page, but the browser (client) renders something different. It’s one of the most common issues in Next.js, especially if you're using dynamic content, third-party scripts, or certain hooks like useEffect. In this blog, we’ll cover, What is Hydration in Next.js? What causes hydration errors in Next.js ? How to debug and fix ? Best practices to avoid. What is Hydration in Next.js? Hydration is the process where react attaches interactivity to a pre-rendered HTML page. Server-side rendering (SSR): The server sends fully rendered HTML to the browser. Client-side hydration: React reuses this HTML but adds event listeners and dynamic content. In short, If what the server rendered doesn’t match what the client renders, you get a hydration error. Common Causes of Hydration Errors & Fixes 1. Mismatched Content Between Server & Client Problem: If the server and client render different content, React will throw a hydration error. Example: The server renders a fixed timestamp when it builds the page. The client re-renders with the current time, causing a mismatch. ✅ Fix: Wrap dynamic content inside useEffect() ✔ Now, the server renders a placeholder (""), and the client updates the time after hydration. 2. Using window, document, or localStorage in SSR Problem: Server-side rendering (SSR) happens before the browser loads, so window, document, and localStorage don’t exist. Example (Incorrect Usage): ❌ Error: window is not defined on the server ✅ Fix: Use useEffect() to access window on the client side. ✔ Now, the server renders an empty value (0), and the client updates it after hydration. 3. Using Random or Time-Based Values in Server Components Problem: Values like Math.random() or Date.now() generate different results on the server and client, causing a mismatch. Example (Incorrect Usage): ✔ Fix: Generate the value only on the client side using useState & useEffect. 4. Conditional Rendering Based on Client Data Problem: If a component renders differently on the server and client, React will throw a hydration error. Example: ❌ Error: navigator is only available on the client ✅ Fix: Use useEffect() to update after hydration 5. Third-Party Scripts Running on the Server Problem: Some third-party libraries (e.g., charts, ads, analytics) try to run on the server but rely on the browser. ✅ Fix: Use dynamic() with { ssr: false } ✔ Now, the component only loads in the browser, preventing hydration issues. Best Practices to Avoid Hydration Errors Always use useEffect() for client-specific code (e.g., window, document, localStorage) Use placeholders or default values for SSR-rendered content Wrap third-party libraries with dynamic() and ssr: false Avoid using random values (Math.random(), Date.now()) directly in server-rendered components Use useState() for dynamic values and update them in useEffect() Conclusion ### How to Optimize or Improve Google Page Speed in Next.js? URL: https://swhabitation.com/blogs/how-to-improve-google-page-speed-in-nextjs Published: 2025-03-03T00:00:00.000Z | Updated: 2025-03-06T17:15:56.000Z | Author: SW Habitation | Category: Next Js A slow website is so frustrating for end-users and too bad for SEO. If your Next.js site takes too much time to load, visitors might leave your website before they even see your content. Google also ranks faster websites higher, so speed is the most important thing. Next.js is built for performance, and with a few simple customization, you can make your site load faster and score well on Google PageSpeed Insights. In this blog, we are going to learn, Why speed matters for SEO and user experience ? Common reasons why Next.js sites are slow. Easy ways to optimize your site for faster loading times. Why Page Speed Matters ? A slow website can cause, High bounce rates: End users leave your website if a page of it takes too much time to load. Lets see what the Bounce Rate is ? Its a metric that measures the percentages of website visitors who leave the website after viewing only one page. It shows how your website is connected with users. Lower SEO rankings: Google prefers fast loading websites. Poor user experience: Nobody likes waiting for a page to load. Google measures website performance using Core Web Vitals, which include: Largest Contentful Paint (LCP) LCP : How long it takes to load the biggest element on your page. The largest element is generally a featuer image or any h1 tag, including below as well, Image element Image element inside svg Video element Any element with background image that loaded vis url() function Block level elements that containing textor other inline level elements text. The first frame of an animated image format, like any animated GIF Image inside video element Anything that the outside of the viewport or any overflow as well is not considering while measuring the LCP. For example, If any image occupies the entire viewport its not considered for LCP. A good LCP value is less than 2.5 seconds [< 2.5 seconds].It sholuld be based on chrome user experience report (CrUX) data. Good: <=2.5s Needs improvement: >2.5s and <=4s Poor: >4s First Input Delay (FID) FID : How quickly your page responds to user actions. The user interactions in terms of, Click on any link or button Input any text into blank field Clicking checkbox Selecting any dropdown menu Events like scrolling or zooming are excluded A good FID value is less than 100 ms. It should be based on Chrome User Experience Report (CrUX) data. now what is CrUX data ? Its a data from the actual users of chrome who are on your site. You need 75% of interactions to respond in less than 100ms. Good: <=100 ms Needs improvement: >100 ms and <=300 ms Poor: >300 ms Cumulative Layout Shift (CLS) CLS : How stable your page layout is while loading. CLS is calculated during the 5 second duration while the most shifing occurs. The main reason behind this occurs is when you try to click somthing ona page that shifts and then ending up by clicking on somthing you dont want to. Common scenarios are below, Images without dimensions [ widht and height ] Content with javascript Any ads, embeds, and iframes without dimensions Web fonts that causes FOIT [Flash of Invisible Text] or FOUT [Flash of Unstyled Text] Javascript animations Content that appears after the page load A good CLS value is less than or equal to 0.1. It should be based on Chrome User Experience Report (CrUX) data. Good: <=0.1 Needs improvement: >0.1 and <=0.25 Poor: >0.25 Now, let’s look at how to improve page speed in Next.js ? Easy Ways to Optimize Page Speed in Next.js 1. Optimize Images with Next.js Component In our regular HTML, we have added any image like below snippet, We have to manually optimize below things, Image is responisive based on the screen sizes Optimize image with any third party toll or library As the image is about to enter on viewport lazy load them. Large images may slow down websites. Next.js provides an optimized component that, Lazy loads images (loads them only when needed) Automatically converts them to modern formats like WebP Resizes images for different screen sizes Use this instead of regular tags: Use priority={true} for images above the fold (visible when the page first loads). 2. Use Static Site Generation (SSG) for Faster Loading If your page doesn’t change frequently then pre-render it at the build time using SSG. This makes it load quickly without waiting for a server response. Example of SSG in Next.js: ✔ It is best for blogs, landing pages and marketing webistes. 3. Enable Incremental Static Regeneration (ISR) for Updated Content If your content changes frequently, but you still want the speed of SSG, use ISR. This updates static pages without rebuilding the entire website. Lets check this by an xample of ISR, ✔ It is perfect for news sites, blogs, and product pages. 4. Load JavaScript Only When Needed Too much javascript may slow down a website. Next.js allows lazy loading, which means scripts load only when required. Lazy load large components: This speeds up initial page load. Lazy load third-party scripts like Google Analytics: ✔ It reduces unnecessary network requests. 5. Reduce Unused CSS and JavaScript For Tailwind users, use PurgeCSS to remove unused styles. Analyze your JavaScript bundle with Webpack Bundle Analyzer: Add below code-snippet to next.config.js, Then run, 6. Use a CDN (Content Delivery Network) for Faster Loading A CDN stores your website files on multiple servers worldwide, so users can load them from the nearest location. Deploy on Vercel (best CDN for Next.js): ✔ Global content distribution ✔ Automatic performance optimizations 7. Optimize Fonts for Faster Rendering Fonts can slow down page load times, so use Next.js Google Fonts Optimization instead of manually importing fonts. next/font will automatically optimize your fonts including custom fonts and remove external network requests for improved privacy and performance. Lets get started by importaing the font you would like to use from next/font/google as a function. Nextjs recommended using variable fonts for the best performance and flexibility. To use the fonts in all your pages, add it to _app.js file under /pages, If you cant use a variable font, you will need to specify a weight, You can specify multiple weights and or styles by using an array, Tip : Its a good practise to use (_) for font names with multiple words. Just like Roboto Mono will be importaed as Roboto_Mono. You can also use the font without a wrapper and classname by adding it inside the just like below at pages/_app.js, ✔ Reduces render-blocking resources ✔ Improves Core Web Vitals Conclusion ### Why Next.js Is Ideal for Headless CMS Integration ? URL: https://swhabitation.com/blogs/nextjs-with-headless-cms Published: 2025-02-25T00:00:00.000Z | Updated: 2025-02-25T05:36:40.000Z | Author: SW Habitation | Category: Next Js Introduction Nowadays, Headless CMS have become widely popular because they separate content management from frontend view. This allows developers to use flexible, API-driven content delivery, that makes websites load faster and more scalable. Next.js, a powerful and most popular React framework, is one of the best choices for integrating a headless CMS. It offers server-side rendering (SSR), static site generation (SSG), API routes, and optimized performance, making it an perfect match for headless CMS platforms like Strapi, Contentful, Sanity, WordPress (headless mode). In this blog, we’ll going to learn, What a headless CMS is and how it works ? Why Next.js is a perfect fit for headless CMS integration ? The benefits of using Next.js with a headless CMS. A step-by-step guide to integrating a headless CMS with Next.js. The best headless CMS options for Next.js. Let’s get started by exploring what the headless cms is ? What is a Headless CMS? Headless CMS is a content management system that separates the information and presentation. Too much technical stuff right ? Lets understand in simple tone, A Headless CMS [Content Management System] is a tool or system that helps you create and manage content like images, text, videos,etc for your website, but it doesn’t decide how that content is shown. Let's think of it like a library where you store your books [here its content]. A regular CMS just like wordpress is like having the librarian not only store the books but also show them to you on a shelf. A headless CMS is like a library where you store the books, but it leaves it up to you or a dedicated developer to decide where and how to display them. So, in simple texts: it focuses on content storage and lets you deliver that content anywhere you desire. How a Headless CMS Works ? Your content is created and stored in the headless CMS. The CMS provides a REST or GraphQL API to fetch the respective content. Next.js consumes the API and displays content dynamically. Above decoupled architecture makes content management more flexible, scalable, and future-proof. Why is Next.js Perfect for Headless CMS Integration ? Next.js widely offers multiple rendering methods , API routes, and built-in optimizations that make it an perfect choice for working with headless CMS platforms. 📌 Server-Side Rendering (SSR) for Real-Time Content Best for: Blogs, news websites, and dynamic pages. Next.js supports SSR, meaning content can be fetched from the headless CMS at request time. This is useful for sites that require real-time updates without needing a full rebuild. 📌 Static Site Generation (SSG) for SEO & Performance Best for: Marketing sites, landing pages, and product pages. SSG [Static Site Generation] allows Next.js to pre-render pages at build time, reducing server load and improving SEO and performance. 📌 API Routes for Custom CMS Logic Next.js allows you to create API endpoints within your project, enabling custom CMS logic like webhook handling or content transformations. 📌 Incremental Static Regeneration (ISR) for Hybrid Content Updates Best for: E-commerce, blogs, or pages needing periodic updates. With ISR, you can update static pages without rebuilding the entire site, making Next.js extremely efficient for dynamic content. 📌 Image Optimization for Faster Loading Next.js automatically optimizes images fetched from a headless CMS, improving performance and Google PageSpeed scores. Step-by-Step Guide: Integrating a Headless CMS with Next.js Please follow these below steps to integrate a headless CMS with Next.js, Step 1: Choose a Headless CMS Below is the popular headless cms options among which you can make a perfect decision for your website, Strapi – Self-hosted, open-source CMS. Contentful – API-first, cloud-based CMS. Sanity – Real-time collaborative content editing. WordPress (Headless) – Familiar but decoupled CMS. Step 2: Fetch Data from the CMS API Please use getStaticProps [for static sites] or getServerSideProps [for real-time updates] to fetch data. Step 3: Display Content in Next.js Pages Map through the fetched data to display it dynamically. Step 4: Deploy to Vercel for Best Performance Next.js is optimized for Vercel, which ensures seamless deployment and global CDN distribution. Best Headless CMS Options for Next.js 1. Strapi Website : https://strapi.io/ Best For : Self-Hosting & Customization Open-source & self-hosted REST & GraphQL APIs 2. Contentful Website : https://www.contentful.com/ Best For : Best for Enterprises & Cloud Hosting Supports structured content modeling Fully managed & scalable 3. Sanity Website : https://www.sanity.io/ Best For : Best for Real-Time Collaboration Supports real-time updates Great for multi-user content teams 4. WordPress Website : https://wordpress.org/ Best For : Headless Mode for Familiarity Easy for non-technical content editors Uses WordPress REST API Conclusion ### Flowbite - A Beginner’s Guide to UI Components for Tailwind CSS URL: https://swhabitation.com/blogs/flowbite-beginners-guide-ui-components-tailwind-css Published: 2025-02-21T00:00:00.000Z | Updated: 2025-04-30T14:57:14.000Z | Author: SW Habitation | Category: CSS Introduction Creating a modern and visually appealing website can be a nightmare, especially when working with design consistency and responsiveness. One of the drawbacks of tailwind compared to other frameworks is that it does not have a set of components. This is where flowbite comes into picture. Flowbite is a powerful UI component library built for Tailwind CSS that makes it easy to create professional look and like websites without writing custom CSS from scratch. If you're a developer using Tailwind CSS, Flowbite can significantly speed up your development process with its pre-styled components, interactive elements, and design system. In this guide, we'll cover: What Flowbite is and how it works ? Key features and benefits of using Flowbite. Installation and usage in a Tailwind CSS project. Flowbite alternatives and when to use them. Let’s deep dive in! What is Flowbite? Flowbite is a component library designed for Tailwind CSS. It provides a ready-made collection of UI elements like buttons, modals, forms, navigation bars, and more. It follows Tailwind CSS's utility-first approach but adds its own pre-built, interactive components that work with vanilla JavaScript or frameworks like React, Vue, and Angular. Flowbite helps us by, Save time by using pre-designed UI components. Maintain a consistent design system across projects. Reduce custom CSS and focus on functionality. Easily combine with Tailwind CSS-based projects. Key Features of Flowbite How to Install Flowbite in a Tailwind CSS Project Using NPM Flowbite can be easily installed into your project using NPM [Node Package Manager] 1. Install Tailwind CSS (if not already installed) Before using Flowbite, please ensure that have you installed tailwind CSS in your project or not. If not then start installing by below command, 2. Install Flowbite Please use npm or yarn to add Flowbite to your project, 3. Enable Flowbite in Tailwind Config Update your tailwind.config.js file to include Flowbite, 4. Use Flowbite Components Now, You can use flowbite components in your HTML or React project. For example, Lets see a flowbite styled button, Or a Flowbite modal like below, How to Install Flowbite in a Tailwind CSS Project Using CDN ? Let’s get started by including the css file inside the head tag of your HTML file. Just like above you can also include the javascript file before the closure of the body tag. By including both the files using CDN on their respective places you have now successfully integrated flowbite in your project. Exploring the components of flowbite Let's get started with exploring the components from flowbite. You can see many more components like alerts, buttons, modals, dropdown menus, datepickers and many more. You can check out many more components from here. Now, all you need to do is to just copy & paste the element of your choice inside your respective project and use them with any hassle. Exploring Pro version There is also a pro-version available for further more flexibility which includes tailwind css figma design kit that you can use to prototype your website design before actually coding it. In this pro version, you will get a lot of useful application ui, marketing ui and e-commerce pages that can help you get started with your project even faster way. You can check out the pricing differences here. Pros & Cons of Flowbite Speeds up UI Development – No need to build components from scratch Compatible with Tailwind CSS – Designed to work natively with Tailwind Fully Responsive – Works across all devices Supports Dark Mode – Matches modern UI trends Limited Free Components: Some advanced components require Flowbite Pro Requires Tailwind CSS Knowledge: Not suitable for projects using other CSS frameworks JavaScript Dependencies: Interactive components rely on vanilla JS, which may not fit all frameworks Limited Customization: Customizing beyond the provided options can sometimes be challenging, especially for beginners. Explore Best Alternatives to Flowbite If you’re looking for other tailwind CSS component libraries, please consider below options, 1. DaisyUI Website : https://daisyui.com/ Best for Utility-First Design. Extends tailwind with additional custom UI components. Free and open source. If you want to know more respective to this topic you can also surf, What is DaisyUI? Advantages, Disadvantages, and FAQ’s 2. Headless UI Website : https://headlessui.com/ Best for Fully Customizable Components Focuses on accessibility and interactivity Works with React and Vue 3. Tailwind UI Website: https://tailwindui.com/ Official Tailwind CSS Library Designed by the Tailwind CSS creators Offers premium pre-built UI kits Conclusion ### Squido: A Beginner’s Guide to the HTML Website Generator URL: https://swhabitation.com/blogs/squido-html-website-generator Published: 2025-02-20T00:00:00.000Z | Updated: 2025-02-20T15:56:47.000Z | Author: SW Habitation | Category: HTML 5 Creating a website from scratch can be a nightmare, especially for any absolute beginners. That’s where Squido, an HTML website generator, comes in. Squido helps users create static websites quickly, without requiring any absolute coding knowledge. Squido is a dead simple, open source static HTML website builder, which is built with nodejs. It can be hosted anywhere for a super fast website. Whether you're a developer looking for a simple way to generate HTML pages or a beginner trying to build a website, Squido is fit for any requirements. Website: https://squido.markmoffat.com/ Github: https://github.com/mrvautin/squido Language : Javascript, nodejs License : MIT Templates : Mustache, Handlebars, Yaml, Markdown In this blog, we’ll learn: What Squido is and how it works ? Key features of Squido Advantages and disadvantages of Squido Installation Install the squido cli module globally in order to build and manage your static site. From github [Preferred for latest versions] Using npm or yarn, If you want to start from default blog setup then go through below steps, Make your squido website directory with below command, Get into the installed directory, It’s a blank directory, now to setup a new squido website from defaults, enter below command, In you want to start from scratch then,follow the below commands, First make your squido directory by below command, Get into the directory by below command, If you want to start from a template. You can use below blog example of squido, https://github.com/mrvautin/squido-blog-example They provide a documentation website example as well you can check it out as well. Please replace my-squido-website with your new website directory name. Now, Run the below command to to build,clean, server and watch for any changes, By this command you can visit your website on the go, http://localhost:4965 Clean => It removes everything in your /build directory. Serve => It starts a web server by which you can view your website. You can see their demos by below links, Blog style: https://squido-blog.markmoffat.com Documentation style: https://squido-docs.markmoffat.com/getting-started/ Traditional website: https://squido.markmoffat.com Key Features of Squido ✔ No Coding Required: Perfect for beginners who don’t know HTML or CSS. ✔ Lightweight & Fast: Generates static HTML pages for fast performance and SEO benefits. ✔ Easy Deployment: Works with platforms like GitHub Pages, Vercel, and Netlify. ✔ Customizable Templates: Choose from pre-designed templates or create your own. ✔ SEO-Friendly: Clean HTML structure ensures better search engine rankings. ✔ No Database Required: Eliminates the need for databases, making websites more secure and efficient. ✔ Swagger API doc: It enables swagger (https://swagger.io/) and generates your super fast static API documentation. ✔ Markdown Supported: All the blog posts and pages are written in markdown format which is easy to learn and faster to write as well. Advantages & Disadvantages of Squido Advantages: Super Fast Performance: Squido generates pure HTML, there’s no need for database queries or server-side processing, which makes websites load quickly. Better Security: Static websites are less risky to attacks like SQL injection or wordpress malware. Easy to Maintain: Its easy to maintain as there is no need for constant updates, backups, or database management. Good for SEO: Google prefers fast-loading, static web pages, Aa squido-generated websites have an SEO advantage. Disadvantages: Not for Dynamic Websites: Squido is great for static pages but not good for blogs with comments, user accounts, or any real-time updates. Limited Customization: Squido supports templates,but it may not be as flexible as full CMS platforms like most popular among cms one and only wordpress. No Built-in CMS: If you want a content management system [CMS like wordpress],then you’ll need a different solution. Conclusion ### How to add Adobe Fonts in Next.js ? URL: https://swhabitation.com/blogs/how-to-add-adobe-fonts-in-nextjs Published: 2025-02-16T00:00:00.000Z | Updated: 2025-02-16T10:28:01.000Z | Author: SW Habitation | Category: Next Js Adobe Fonts, formerly a Typekit, offers a wide range of high-quality fonts that can give your Next.js website a professional and unique look. Unlike the Google Fonts, which can be self-hosted via next/font/google, Adobe Fonts requires a slightly different approach. Let's see what that is… This blog will cover below important points, How to get Adobe Fonts API link ? What is best way to integrate Adobe Fonts in Next.js ? How to use local hosting for better performance Optimizing Adobe Fonts for better Core Web Vitals ? Let’s get started! Install Adobe Fonts 1. Sign Up for Adobe Fonts Before you begin, you’ll need an Adobe account. If you don’t have one yet, just sign up on Adobe Fonts. https://fonts.adobe.com/ 2. Pick Your Fonts Browse through the font library and pick the ones you love and perfect for your website. There's a huge selection, so you're sure to find something perfect for your site. Once you've found a font you want to use, click on it and then hit Add to Web Project. 3. Create a Web Project When you add a font to your project, Adobe will ask you to create a Web Project. Just give your project a name (something like “My Awesome Website Fonts” or something you like), and pick the font styles you want (like bold or italic). This helps you only load the ones you need, making your site faster. 4. Copy the Embed Code Once your project is ready, Adobe will generate a special embed code for you. Please Copy the code — it’s a simple tag that you’ll use in your website’s HTML. 5. Add the Code to Your Website Open your website’s HTML file. Paste the embed code into the section of your page, like this: This links your website to the fonts you just picked. 6. Use the Fonts in Your CSS Now that the fonts are connected to your website, it’s time to apply them! In your CSS file, you can use the font like this: Save your changes, refresh your website, and voilà! Your new fonts should be live on your site. Lets see how this magic works on next.js as well. Add Adobe Fonts in Next.js Method 1: Using in _document.js which is Recommended for SEO & Performance. Since Next.js optimizes font loading, adding Adobe Fonts to _document.js ensures styles are applied efficiently. => Open pages/_document.js and add the Adobe Fonts link inside This method loads fonts early and ensures no layout shift (CLS). and Fonts will be cached, improving performance. Method 2: Adding Adobe Fonts in _app.js or a Global CSS File Alternatively, you can import the Adobe Fonts CSS in _app.js or your global styles file. Option A: Import in _app.js Then, add the Adobe Fonts import inside globals.css: Option B: Load Fonts Dynamically in a Component If you want to load fonts only when a specific component is used, you can do: Use this method if you need fonts in specific pages only. Using Adobe Fonts in CSS Once the fonts are loaded, you can use them in CSS files or styled-components. For CSS files: For Styled Components (If Using Emotion or Styled-Components): Optimizing Adobe Fonts for Performance & SEO To ensure fast loading and good Core Web Vitals, follow these tips: ✔ Preload Critical Fonts: If a font is used in the hero section, preload it by adding this inside _document.js: ✔ Limit the Number of Fonts: Too many fonts increase load time. Try to use only necessary weights & styles. ✔ Use Font Display Options: Adobe Fonts does not provide font-display: swap by default, which can cause FOIT (Flash of Invisible Text). To fix this, use: Alternative: Self-Hosting Adobe Fonts in Next.js If you want even faster performance, you can self-host Adobe Fonts instead of loading them from Adobe's CDN. Steps to Self-Host Adobe Fonts: Download the Font Files from Adobe Fonts (if allowed). Place Fonts in /public/fonts/ directory. Define a Font Face in Global CSS: Use the font anywhere: Self-hosting improves performance because fonts are loaded from your own server. Conclusion ### What is Emotion CSS? A Beginner’s Guide URL: https://swhabitation.com/blogs/what-is-emotioncss-beginners-guide Published: 2025-02-11T00:00:00.000Z | Updated: 2025-02-16T09:24:02.000Z | Author: SW Habitation | Category: CSS By the end, you’ll understand: What Emotion CSS is and why it's popular ? How to use Emotion in your project ? What is the differences between Styled Components and Emotion ? Pros and cons of using Emotion. What is Emotion CSS? First of all Emotion css is a library specially designed for writing css in styles with javascript. It provides predictable style composition for great developer experience. Website : https://emotion.sh/docs/introduction Github : https://www.npmjs.com/package/@emotion/css It provides two ways to style components: 1. Styled Components : Similar to the styled-components library. 2. CSS Prop : A lightweight way to use Emotion without creating separate styled components. Since styles are written inside JS files, you get dynamic theming, scoped styles, and better maintainability all things while keeping performance higher. Why Use Emotion? 1. Scoped Styles (No More Global Conflicts!) What if I say forget about class name conflicts ? Emotion generates unique class names, you don’t have to worry about styles affecting accidental elements. 2. Dynamic Styling with Props With Emotion css, styles can change based on component props, which makes it easy to create theme aware components. 3. Automatic Vendor Prefixing No need to manually add browser prefixes like -webkit- or -moz-. Emotion handles it for you. 4. Better Performance Than Traditional CSS Emotion removes unused styles and only loads what's necessary, making pages load faster. 5. Works with Server-Side Rendering (SSR) Unlike some CSS-in-JS solutions, Emotion works great with SSR (important for Next.js apps!). How to Use Emotion CSS ? There are two packages available, one is @emtion/core and the other one is @emotion/styled, which powers the styled-components. We will see the second one here, Install Emotion Run the following command to install Emotion in your project: OR if you're using yarn: Using Emotion’s Styled Components API If you've used Styled Components, Emotion’s styled API will feel familiar. The Button component is now fully styled and reusable! Using the CSS Prop (Alternative Method) You can also style elements inline using the css prop instead of styled components. When to Use styled vs. css Prop? Use styled when you want reusable components. Use css prop when you need one-off styles without creating extra components. Theming with Emotion Want to apply global styles and themes? Emotion supports Theme Providers to make styling even more flexible. Now, your styled components can access the theme like this: Emotion vs. Styled Components: Which One to Use? If you need better performance, the CSS prop, and smaller bundle sizes, Emotion is the better choice. If you’re already using Styled Components, Emotion’s styled API feels familiar, so it’s easy to switch. Pros & Cons of Using Emotion Pros: Scoped styles prevent conflicts. Dynamic styling based on props. Optimized for performance and SSR. No extra setup for vendor prefixes. Works with Next.js, React, and TypeScript. Cons: Slightly different syntax if you’re used to traditional CSS. Requires additional dependencies. Might feel unnecessary for small projects. Conclusion ### How to Generate a Dynamic Sitemap in Next.js ? URL: https://swhabitation.com/blogs/how-to-generate-dynamic-sitemap-nextjs Published: 2025-02-08T00:00:00.000Z | Updated: 2025-02-10T05:57:11.000Z | Author: SW Habitation | Category: Next Js In this blog, we’ll learn: Why sitemaps matter for SEO ? How to generate a dynamic sitemap in Next.js ? How to automatically update it when content changes ? At the end, your Next.js site will have a fully functional sitemap that keeps search engines happy go lucky and boosts your rankings on next level. Why Do You Need a Dynamic Sitemap in Next.js ? A sitemap.xml file tells Google which pages exist on your website. It’s especially useful when: You have a big website with multiple pages. Your site updates frequently, like a blog or e-commerce store. You want to improve SEO and indexing speed. Instead of manually updating a sitemap every time you publish a new page, we’ll generate it dynamically in Next.js so it always stays up to date! Step 1: Create a Dynamic API Route for Sitemap, In Next.js, we can create a dynamic sitemap using an API route that fetches URLs from a database or CMS. 1. Inside the pages/api/ folder, create a new file: => pages/api/sitemap.xml.js 2. Add this below code-snippet to generate the sitemap: What This Code Does ? => Fetches dynamic pages from getAllPages(). => Generates an XML sitemap dynamically. => Sends it as a response when /api/sitemap.xml is requested. Step 2: Make Sitemap Available at /sitemap.xml Now, let’s make sure Google can access it. so, open next.config.js and add below code snippet, When you visit example.com/sitemap.xml, it will serve the dynamically generated sitemap! Step 3: Submit Your Sitemap to Google Search Console Go to Google Search Console. Select your website. Click Sitemaps on the left. Enter sitemap.xml (e.g., https://example.com/sitemap.xml). Click Submit! Google will now automatically crawl and index your pages whenever they update. Bonus: Automatically Rebuild Sitemap on Content Changes If your content updates frequently, you can revalidate the sitemap automatically using Next.js Incremental Static Regeneration (ISR). Modify your API route (sitemap.xml.js) like below: This ensures that Google always gets the latest version of your sitemap! Conclusion ### How to Set Up ESLint, Prettier, and Husky in Next.js ? URL: https://swhabitation.com/blogs/how-to-setup-eslint-prettier-husky-nextjs Published: 2025-02-04T00:00:00.000Z | Updated: 2025-02-08T12:48:27.000Z | Author: SW Habitation | Category: Next Js These 3 together helps you with, Automatically format your code. Find bugs and syntax errors so early. Implement best coding practices. Conforms high-quality code before every commit. In this blog, We’ll guide you through setting up ESLint, Prettier, and Husky in a Next.js project to take your developer workflow to the next level. Let's discuss What are these tools? 1. ESLint Website: https://eslint.org/ Eslint is a static code analysis tool that checks your JavaScript/TypeScript code for errors and applies coding standards. Think of it as a spell-checker for your code. 2. Prettier Website : https://prettier.io/ Prettier is the opinionated code formatter that automatically formats your code to make it consistent and readable.it supports so many languages. 3. Husky Website : https://typicode.github.io/husky/ Husky is a tool that adds Git hooks to your project, so you can run scripts like linting and formatting before making a commit or pushing code into your respective github. Why Use Them Together? ESLint ensures code quality. Prettier keeps your code neat and tidy. Husky prevents messy or broken code from being committed. By combining them, you’ll save time, avoid unnecessary bugs, and make life easier for your project team. Step 1: Initialize a Next.js Project If you don’t already have a Next.js project, let's create one, Step 2: Install ESLint and Prettier Next.js comes with ESLint support out of the box, but we’ll install Prettier and configure both. First install dependencies, Run the following command to install ESLint, Prettier, and some helpful plugins: Why These Plugins? eslint-config-prettier: Turns off ESLint rules that might conflict with Prettier. eslint-plugin-prettier: Runs Prettier as an ESLint rule, so you see formatting issues directly in your editor. Step 3: Configure ESLint and Prettier Update the .eslintrc.json File Edit your ESLint configuration file (.eslintrc.json) like this: Add a Prettier Configuration File, Create a prettier.config.js file in the root of your project: Step 4: Test Your Setup Run ESLint to check your code: To format your code with Prettier, add a script to your package.json: Now, run: Your code should now be linted and formatted! Step 5: Install Husky for Git Hooks Now let’s set up Husky to enforce these checks before commits. Install Husky : Run the following command: Initialize Husky : Enable Husky in your project: This will create a .husky directory in your project. Step 6: Add Pre-Commit Hook Husky allows you to run scripts before commits. Let’s add a pre-commit hook to run ESLint and Prettier. Create the Hook This command will add a pre-commit file to your .husky folder with the following script: Now, every time you commit code, Husky will run linting and formatting checks automatically. Step 7: Test the Workflow 1. Make some changes to your code. 2. Stage the changes: 3. Commit the changes: If there are any linting or formatting issues, the commit will be blocked until you fix them. Final Directory Structure After completing the setup, your project directory should look like this: Benefits of Using These 3 Tools Together Consistency: Everyone on your team writes code in the same style. Fewer Bugs: Catch errors early with ESLint. Streamlined Workflow: Husky enforces good practices automatically. Time-Saving: No more manual code formatting or debugging inconsistent styles. Conclusion ### How to Use CSS Modules in Next.js ? : A Beginner-Friendly Guide URL: https://swhabitation.com/blogs/how-to-use-css-modules-nextjs Published: 2025-02-03T00:00:00.000Z | Updated: 2025-02-08T12:47:29.000Z | Author: SW Habitation | Category: CSS Styling is a main part of any website. CSS Modules provides a great way to write scoped, maintainable CSS in Next.js. Unlike traditional global CSS, which applies styles to the entire project, CSS Modules allow you to style components individually without worrying about name conflict in the whole project. ? How to apply dynamic styles ? Best practices and common mistakes. So, Let’s dive in! What Are CSS Modules? CSS Modules locally scope css by automatically creating a unique class name.Now, all class names are accordingly scoped to the specific component they are used in. This thing prevents style conflicts and makes styling more predictable. No more class name conflicts! Cleaner, component-specific styles Works natively with Next.js (no extra setup needed) Creating a Next.js Project If you don’t have a Next.js project yet, create one using: Using CSS Modules in Next.js By default, Next.js supports CSS Modules right away. You just need to follow the correct file naming convention: Create a CSS Module file inside your component’s folder. Import the styles in your component. Apply styles using className={styles.className}. For Example, Lets Style a Component with CSS Modules, # Create a CSS Module file: Create a new file called Button.module.css inside the styles/ folder (or next to your component). # Import and use it in a component: Now, when you use