Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 20, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      May 20, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 20, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 20, 2025

      Helldivers 2: Heart of Democracy update is live, and you need to jump in to save Super Earth from the Illuminate

      May 20, 2025

      Qualcomm’s new Adreno Control Panel will let you fine-tune the GPU for certain games on Snapdragon X Elite devices

      May 20, 2025

      Samsung takes on LG’s best gaming TVs — adds NVIDIA G-SYNC support to 2025 flagship

      May 20, 2025

      The biggest unanswered questions about Xbox’s next-gen consoles

      May 20, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      HCL Commerce V9.1 – The Power of HCL Commerce Search

      May 20, 2025
      Recent

      HCL Commerce V9.1 – The Power of HCL Commerce Search

      May 20, 2025

      Community News: Latest PECL Releases (05.20.2025)

      May 20, 2025

      Getting Started with Personalization in Sitecore XM Cloud: Enable, Extend, and Execute

      May 20, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Helldivers 2: Heart of Democracy update is live, and you need to jump in to save Super Earth from the Illuminate

      May 20, 2025
      Recent

      Helldivers 2: Heart of Democracy update is live, and you need to jump in to save Super Earth from the Illuminate

      May 20, 2025

      Qualcomm’s new Adreno Control Panel will let you fine-tune the GPU for certain games on Snapdragon X Elite devices

      May 20, 2025

      Samsung takes on LG’s best gaming TVs — adds NVIDIA G-SYNC support to 2025 flagship

      May 20, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»Basset is an alternative way to load CSS & JS assets

    Basset is an alternative way to load CSS & JS assets

    April 17, 2024

    It’s 2024 and I’m calling it – Server-Side Rendering has officially made a comeback:

    in Laravel, where Livewire now has 46.000 installs per day

    in Ruby on Rails with Hotwire
    in Phoenix with Liveview
    in web dev in general with HTMX

    Now that “the old has become the new“… maybe it’s time to re-visit another practice we’ve adopted from the Javascript ecosystem. Maybe it’s time to… drop the build step? Crazy, I know! But there’s been a lot of talk about no-build Laravel setups in my bubble. And there’s one place where people invariably get stuck – “If we drop NPM, what do we do about JS dependencies?“. Here’s my answer to that – or at least an important first step.

    What if instead of installing our JS dependencies with a package manager like NPM and bundling them… we just load them directly from the URL? You know… similarly to what the founder of NodeJS himself is doing in Deno. He has publicly said NPM has become a mess and created an alternative for the JS ecosystem… why don’t we do the same for the Laravel ecosystem?

    If you dream about the simple days when you could just load assets using asset(), try Basset – a better asset helper for Laravel. You just replace asset() with basset() to gain some super-powers:

    assets from CDNs are downloaded to /storage and served from there;
    vendor assets become possible to load;
    non-public assets become possible to load;
    it becomes impossible to double-load an asset during a request;

    In short, basset() removes the limitations of asset(), allowing you to load any asset you want, safely. That means in addition to this:

    <link href=”{{ asset(‘path/to/public/file.css’) }}”>

    You can safely do this:

    <script src=”{{ basset(storage_path(‘file.js’)) }}”>
    <script src=”{{ basset(base_path(‘vendor/org/package/assets/file.js’)) }}”>
    <script src=”{{ basset(‘https://cdn.com/path/to/file.js’) }}”>

    This is a very simple solution for those who want to load assets “the old easy way” in their Laravel projects, because it solves a few problems with that “old way“:

    Don’t want GDPR issues?

    ✅ Solved – Basset will cache the asset to /storage and serve it from there.

    Hostinger

    Don’t want to depend on a CDN being up?

    ✅ Solved – the assets can be cached upon deployment (or on commit).

    Don’t want to load an asset twice, if used by multiple components on that page?

    ✅ Solved – automatically.

    Concerned about the performance of loading multiple JS files vs one big bundle?

    ✅ Solved by HTTP/2, which makes it performant to load multiple Javascript assets on a single page.

    Granted, Basset may not be a perfect asset loading solution. At least not for every project. It’s only been around for 12 months, so it’s missing things like importmaps and the like, to make it a 1-to-1 alternative to NPM and Deno’s way. But it has been around for 12 months and has proven its usefulness.

    Perhaps… it’s time for us to take another look at how we load assets in our Laravel projects. Maybe we’ll discover the simple way… is a good way. For some projects, at least. I suggest you give Basset a try. After all:

    it’s been in production for 1 year already;
    it’s maintained by the Backpack team;
    it’s got 110.000 downloads already;
    it’s under MIT License;

    If you have feedback on it, open an issue on Github and tell the team about it. A v2 is due soon enough, and we want to incorporate as much feedback as possible.

    The post Basset is an alternative way to load CSS & JS assets appeared first on Laravel News.

    Join the Laravel Newsletter to get all the latest Laravel articles like this directly in your inbox.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleScientists accelerate the search for Parkinson’s treatments using AI
    Next Article Russian APT Deploys New ‘Kapeka’ Backdoor in Eastern European Attacks

    Related Posts

    Security

    Nmap 7.96 Launches with Lightning-Fast DNS and 612 Scripts

    May 21, 2025
    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-5011 – MoonlightL Hexo-Boot Cross-Site Scripting Vulnerability

    May 21, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    Superhuman’s Secret Onboarding UX

    Web Development

    CVE-2025-47533 – Graphina CSRF PHP Local File Inclusion Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    How to Redirect Uppercase URLs to Lowercase with Laravel Middleware

    Development

    Digital Wallets at Risk: Is Cyber Insurance Worth It?

    Development

    Highlights

    Development

    Local Model Scopes in Laravel with the Scope Attribute

    April 2, 2025

    Laravel released a new #[Scope] attribute you can use to define local scopes in Eloquent…

    Windows 11 to Deprecate NTLM, Add AI-Powered App Controls and Security Defenses

    May 21, 2024

    Play ransomware exploited Windows logging flaw in zero-day attacks

    May 7, 2025

    Developer Spotlight: Francesco Michelini

    January 17, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.