Masonite Inertia
4.X
4.X
  • Introduction
  • Installation
  • Demo app
  • The basics
    • Routing
    • Responses
    • Redirects
    • Validation
    • Shared data
    • File uploads
  • Advanced
    • Configuration
    • Root view
    • Partial reloads
    • Authorization
    • CSRF protection
    • Error handling
    • Assets versioning
    • Server-side rendering
    • Testing
  • Development
    • Changelog
    • Contribute
    • Support
Powered by GitBook
On this page

Was this helpful?

  1. Advanced

Partial reloads

PreviousRoot viewNextAuthorization

Last updated 3 years ago

Was this helpful?

You can find all details in .

For partial reloads to be most effective, be sure to also use lazy data evaluation server-side.

This can be done by wrapping all optional page data in a callable or the adapter lazy function. When Inertia performs a visit, it will determine which data is required, and only then will it call the function. This can significantly increase the performance of pages with a lot of optional data.

app/http/controllers/UsersController.py
from masonite.inertia import lazy

def show(self, view: InertiaResponse):

    def get_users(request):
        return User.all().serialize()

    return view.render("Users/Index", {
        # ALWAYS included on first visit
        # OPTIONALLY included on partial reloads
        # ALWAYS evaluated
        'users': User.all().serialize(),

        # ALWAYS included on first visit
        # OPTIONALLY included on partial reloads
        # ONLY evaluated when needed
        'users': lambda: _: User.all().serialize(),
        # above can also written as
        'users': get_users
        
        # NEVER included on first visit
        # OPTIONALLY included on partial reloads
        # ONLY evaluated when needed
        'users': lazy(get_users)
    })

For convenience, the request argument will be automatically passed to lazy loaded props. In the example above the get_users will receive the request object (even if not used).

Official documentation