Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Have your cake and eat it with Inertia.js

Have your cake and eat it with Inertia.js

One of the harder choices we need to make as web developers in 2019 is how we want to build our app's frontend.

Do we want to stick with Blade for templating? Do we want to build a SPA? SPA's sound cool but then we'll need an API and use some fancy authentication protocol. We still might want a SPA though, since that'd allow us to provide a richer user experience. Decisions are hard!

Let's take a step back. Instead of choosing between the two ends of the spectrum, why not combine them and have the best of both worlds? That's where Inertia.js makes its appearance. Inertia.js is a framework for creating server-driven single page apps. With Inertia.js, we can build an app that keeps business and data concerns on the server, with a JavaScript powered view layer.

In this talk, we'll review the tradeoffs when making a choice between keeping complexity on the server or on the client. Then we'll demonstrate what an app looks like built with Laravel, Vue.js and Inertia.js.

Sebastian De Deyne

August 30, 2019
Tweet

More Decks by Sebastian De Deyne

Other Decks in Programming

Transcript

  1. Sebastian De Deyne Frontend(ish) developer at Spatie Maintainer of Inertia's

    React adapter Helping out with Inertia About me @sebdedeyne
  2. Complex business apps (form heavy) Require authentication (no SEO concerns)

    No shared public API (MVC) Laravel + React & TypeScript Projects I work on at Spatie @sebdedeyne
  3. Laravel, Symfony, Ruby on Rails Own templating language Blade, Twig,

    ERB Sprinkled with JavaScript Server-side MVC frameworks @sebdedeyne
  4. Build your UI entirely in JavaScript Consume existing APIs Offline

    support Possibly less server load SPAs are awesome! @sebdedeyne ! " # #
  5. JavaScript view layer No API Bonus: less AJAX endpoints Keep

    routing & data fetching on the server Wishlist @sebdedeyne
  6. class Post extends Model { public function getPermissionsAttribute() { return

    [ 'update' !$ Auth!%user()!)can('edit', $this), 'destroy' !$ Auth!%user()!)can('destroy', $this), ]; } }
  7. class User extends Model { public function getPermissionsAttribute() { return

    [ 'post' !$ [ 'viewAny' !$ Auth!%user() !)can('viewAny', Post!%class), 'create' !$ Auth!%user() !)can('create', Post!%class), ], ]; } }
  8. class Post extends Model { public function getLinksAttribute() { return

    [ 'update' !$ action( [PostsController!%class, 'update'], $this ), 'destroy' !$ action( [PostsController!%class, 'destroy'], $this ), ]; } }
  9. Map controller actions to JavaScript components Turbolinks-like navigation
 Preserve page

    state & scroll Partial data reloads Remember state Asset versioning Features @sebdedeyne
  10. No context switching during development Less AJAX endpoints Snappy, no

    full page refreshes Doesn't break browser behaviour What makes Inertia great? @sebdedeyne DX UX
  11. github.com/inertiajs (website & full docs coming soon!) Inertia.js on Twitter:

    @inertiajs Jonathan Reinink: @reinink sebastiandedeyne.com @sebdedeyne Resources