Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Hinclude Laravel Package

mnot/hinclude

Laravel package that adds Server Side Includes (hinclude) support, letting you compose pages from reusable fragments and render parts independently. Useful for micro-frontends, partial caching, and speeding up complex views by loading sections separately.

Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Use Case Alignment: The mnot/hinclude package enables declarative client-side inclusion (e.g., embedding external resources like HTML snippets, partials, or dynamic content) via HTTP headers (X-Include). This aligns well with:
    • Modular PHP/Laravel applications needing dynamic content aggregation (e.g., microservices, headless CMS integrations, or composable UIs).
    • Edge-side includes (ESI) patterns, where fragments are fetched and merged at the client or proxy level (e.g., Varnish, Cloudflare Workers).
    • Progressive hydration strategies (e.g., loading non-critical UI elements post-render).
  • Anti-Patterns:
    • Not a server-side templating engine: Avoid using for traditional PHP template inheritance (e.g., Blade). Better suited for post-render composition.
    • Client-side dependency: Relies on JavaScript execution (via fetch or similar) for inclusion logic. May conflict with SSR/SSG workflows.

Integration Feasibility

  • Laravel Compatibility:
    • Middleware/Response Hooks: Can inject X-Include headers via Laravel’s App\Http\Middleware or Illuminate\Http\Response events.
    • Service Provider: Register a global macro or facade to simplify inclusion syntax (e.g., response()->include('partial')).
    • Blade Integration: Custom Blade directive to mark sections for inclusion (e.g., @includeClient('header')).
  • Frontend Requirements:
    • JavaScript Runtime: Requires a client-side script to process X-Include headers (provided by the package). Ensure compatibility with your JS bundle (e.g., Vite, Webpack).
    • CORS/Headers: External includes must adhere to CORS policies. Configure Laravel’s Access-Control-Allow-Origin if needed.

Technical Risk

Risk Area Mitigation Strategy
Performance Overhead Benchmark inclusion latency (especially for high-cardinality includes). Cache responses aggressively.
Security Validate included URLs to prevent SSRF or XSS (e.g., whitelist domains, sanitize content).
SEO/SSR Conflicts Exclude includes during server-side rendering (e.g., via if (app()->runningInConsole())).
Browser Support Test with legacy browsers if targeting non-modern audiences (e.g., polyfill fetch).
Package Maintenance Monitor for updates (last commit: 2018). Fork if critical bugs arise.

Key Questions

  1. Why Client-Side?
    • Could server-side includes (e.g., Laravel’s @include or partials) achieve the same goal with lower latency?
    • Are there edge caching requirements (e.g., Varnish ESI) that necessitate this approach?
  2. Content Ownership
    • Who hosts the included resources? Internal microservices? Third-party APIs? (Impacts CORS/headers.)
  3. Fallback Strategy
    • How should the app behave if JavaScript is disabled or includes fail to load?
  4. Analytics/Tracking
    • Are included fragments tracked separately? Will this affect GA/GTM implementations?
  5. Build Process
    • How will this integrate with your frontend tooling (e.g., Vite’s SSR, Next.js-like hybrid rendering)?

Integration Approach

Stack Fit

  • PHP/Laravel Stack:
    • Backend: Leverage Laravel’s response pipeline to inject X-Include headers.
    • Frontend: Use the package’s JS library to process includes (or write a custom adapter for your framework, e.g., Alpine.js, React).
  • Non-Laravel PHP:
    • Works with any PHP app, but requires manual header injection (e.g., header('X-Include: ...')).
  • Alternative Stacks:
    • Node.js: Consider hinclude alternatives like html-includes or custom Webpack loaders.
    • Static Sites: Use with tools like eleventy or Hugo via custom shortcodes.

Migration Path

  1. Phase 1: Proof of Concept
    • Isolate a non-critical section (e.g., footer, sidebar) for inclusion testing.
    • Implement a Laravel middleware to inject headers for specific routes.
    • Test with a static JS include script (no build step required).
  2. Phase 2: Build Integration
    • Bundle the JS library into your asset pipeline (e.g., Vite plugin or Webpack require).
    • Add a Blade directive or facade for developer ergonomics.
  3. Phase 3: Full Rollout
    • Replace hardcoded includes with dynamic X-Include headers.
    • Monitor performance and error rates (e.g., failed includes).

Compatibility

Component Compatibility Notes
Laravel Versions Tested on PHP 7.2+ (package last updated for PHP 7.x). Use composer require with version constraints.
Frontend Frameworks Works with vanilla JS, but may need adapters for React/Vue (e.g., custom hooks).
Caching Layers Ensure proxies (Varnish, Cloudflare) forward X-Include headers.
CDNs CDNs may strip custom headers; configure to preserve X-Include.

Sequencing

  1. Backend Setup
    • Add middleware to inject headers:
      // app/Http/Middleware/IncludeMiddleware.php
      public function handle($request, Closure $next) {
          $response = $next($request);
          $response->header('X-Include', 'header,footer');
          return $response;
      }
      
  2. Frontend Setup
    • Include the JS library in your layout:
      <script src="https://unpkg.com/[email protected]/dist/hinclude.js"></script>
      
    • Or bundle it:
      // vite.config.js
      import { defineConfig } from 'vite';
      export default defineConfig({
        plugins: [/* ... */],
        optimizeDeps: { include: ['hinclude'] }
      });
      
  3. Content Markup
    • Add inclusion tags to HTML:
      <div id="header" data-hinclude="/api/header"></div>
      
  4. Testing
    • Validate includes via browser dev tools (Network tab for X-Include headers).
    • Test edge cases (failed fetches, CORS errors).

Operational Impact

Maintenance

  • Dependencies:
    • Monitor mnot/hinclude for security updates (low priority; MIT license).
    • JS library may need polyfills for older browsers (e.g., fetch for IE11).
  • Laravel-Specific:
    • Update middleware/headers if Laravel’s response system changes (e.g., Symfony HTTP message updates).
    • Document the inclusion pattern for future developers.

Support

  • Debugging:
    • Log failed includes (e.g., hinclude events or Laravel’s Log::error).
    • Provide fallback content for critical includes:
      <div id="sidebar" data-hinclude="/api/sidebar" data-fallback="<p>Loading sidebar...</p>"></div>
      
  • User Impact:
    • Communicate loading states (e.g., skeletons) if includes are non-critical.
    • Offer a "no-JS" mode for accessibility compliance.

Scaling

  • Performance:
    • Cache Aggressively: Use Cache::remember for included content if sourced from Laravel.
    • Edge Caching: Configure Varnish/Cloudflare to cache included fragments separately.
    • Lazy Loading: Defer non-critical includes (e.g., data-hinclude with loading="lazy").
  • Load Testing:
    • Simulate high include traffic (e.g., 1000+ concurrent requests) to test backend/API limits.
    • Monitor third-party API rate limits if includes fetch external data.

Failure Modes

Failure Scenario Mitigation
JS Disabled Provide server-rendered fallbacks or use noscript includes.
CORS Blocked Configure Laravel’s CORS middleware or use JSONP if applicable.
API/Include Unavailable Implement retry logic or exponential backoff in the JS library.
Header Stripped by Proxy Whitelist X-Include in CDN/proxy configurations.
Content Mismatch Validate included HTML structure (e.g., schema checks).

Ramp-Up

  • Developer Onboarding:
    • Document the pattern with examples:
      ## Using hinclude in Laravel
      1. Add middleware to inject headers.
      2. Mark HTML with `data-hinclude`.
      3. Include the JS library.
      
    • Provide a CLI command to generate include boilerplate:
      php artisan make:include header /api
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
coleus/frame
thtg88/journalism
filagora/filagora-ai-forums
rlacerda83/query-parser
socialdept/atp-orm
cboxdk/laravel-assistant-client
socialdept/atp-resolver
socialdept/tenant-domains
tautvydasr/blade-class-names
socialdept/color-scales
maherelgamil/controller
coleus/widgets
coleus/table
coleus/users
coleus/music
coleus/health
coleus/calendar
coleus/notes
coleus/support
coleus/settings