GithubHelp home page GithubHelp logo

pborreli / turbolinks-1 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from helthe/turbolinks

0.0 1.0 0.0 118 KB

Helthe Turbolinks Component

License: MIT License

PHP 57.42% CoffeeScript 42.58%

turbolinks-1's Introduction

Helthe Turbolinks

The Helthe Turbolinks is a direct port of the rails turbolinks gem and the jquery.turbolinks gem for projects using the Symfony HttpFoundation Component.

Build Status

Versions

Current versions of the following gems are used:

  • turbolinks: v2.2.0
  • jquery.turbolinks: v2.0.1

Performance

Turbolinks makes following links in your web application faster. Instead of letting the browser recompile the JavaScript and CSS between each page change, it keeps the current page instance alive and replaces only the body and the title in the head.

Performance improvements will vary depending on the amount of CSS and Javascript you are using. You can get up to a 2X increase when using a lot of Javascript and CSS. You can find the rails benchmarks here.

Installation

Using Composer

Manually

Add the following in your componser.json:

{
    "require": {
        // ...
        "helthe/turbolinks": "~1.2"
    }
}

Using the command line

$ composer require 'helthe/turbolinks=~1.2'

Usage

Using turbolinks requires both the usage of the javascript library and modifying the PHP response so that it can be properly processed by turbolinks.

PHP

There are multiple ways to decorate the PHP response for turbolinks.

Manually

You can manually decorate the response with the Turbolinksobject.

<?php
use Helthe\Component\Turbolinks\Turbolinks;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

// ...

$turbolinks = new Turbolinks();
$turbolinks->decorateResponse($request, $response);

Event Listeners

You can add an event listener to the dispatcher that is passed to the HttpKernel.

<?php
use Helthe\Component\Turbolinks\EventListener\TurbolinksListener;
use Helthe\Component\Turbolinks\Turbolinks;

// ...

// Symfony\Component\EventDispatcher\EventDispatcherInterface
$dispatcher->addSubscriber(new TurbolinksListener(new Turbolinks()));

Stack Middleware

You can decorate the response using the supplied Stack middleware.

<?php
use Helthe\Component\Turbolinks\StackTurbolinks;
use Helthe\Component\Turbolinks\Turbolinks;

// ...

$app = new StackTurbolinks($app, new Turbolinks());

Javascripts

Both the original coffeescript version and compiled version of each script are available for use.

Using turbolinks.js

To enable turbolinks, all you need to do is add the compiled turbolinks javascript to your layout in the <head>section.

Using jquery.turbolinks

If you need to use jquery.turbolinks, you need to add it before turbolinks.js.

Compatibility

The turbolinks javascript is designed to work with any browser that fully supports pushState and all the related APIs. This includes Safari 6.0+ (but not Safari 5.1.x!), IE10, and latest Chromes and Firefoxes.

Do note that existing JavaScript libraries may not all be compatible with Turbolinks out of the box due to the change in instantiation cycle. You might very well have to modify them to work with Turbolinks' new set of events. For help with this, check out the Turbolinks Compatibility project.

Additional Resources

Please refer to the turbolinks and jquery.turbolinks projects if you require additional information on the javascript libraries and their usage.

Bugs

For bugs or feature requests, please create an issue.

turbolinks-1's People

Contributors

carlalexander avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.