laravellaravel-5.3varnishesi

ESI tags in Laravel 5.3


For a Laravel 5.3 project I'm currently working on, the breadcrumb should be constructed dynamically based on a certain context. Since we need Varnish on this project I am trying to resort to the use of ESI tags.

I've set up a route that renders the breadcrumb and returns it as follows in routes/web.php:

Route::get('breadcrumbs', 'BreadcrumbController@showBreadcrumb');

This is what the controller looks like:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class BreadcrumbController extends Controller
{
    public function showBreadcrumb(Request $request)
    {
        return 'Breadcrumb';
    }
}

In my template I have the ESI tag defined as follows:

<esi:include src="{{ url('breadcrumbs') }}" />

Now, when I load the page I see the text "Redirecting to /breadcrumbs" at the place where the ESI tag should be rendered. Obviously I then get redirect to /breadcrumbs and see the output of my controller.

How can I stop this redirect behaviour and just have Laravel return the needed output?


Solution

  • Turns out, the localization middleware I was using on my web routes was causing the redirect. It redirected any route without a language prefix.

    I'm using mcamara/laravel-localization. Removing the middleware from my breadcrumbs route fixed the problem.