[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-70681":3},{"id":4,"name":5,"fullName":6,"owner":5,"repo":5,"description":7,"homepage":8,"htmlUrl":8,"language":9,"languages":8,"totalLinesOfCode":8,"stars":10,"forks":11,"watchers":12,"openIssues":13,"contributorsCount":14,"subscribersCount":14,"size":14,"stars1d":12,"stars7d":12,"stars30d":12,"stars90d":14,"forks30d":14,"starsTrendScore":15,"compositeScore":16,"rankGlobal":8,"rankLanguage":8,"license":17,"archived":18,"fork":19,"defaultBranch":20,"hasWiki":18,"hasPages":19,"topics":21,"createdAt":8,"pushedAt":8,"updatedAt":22,"readmeContent":23,"aiSummary":24,"trendingCount":14,"starSnapshotCount":14,"syncStatus":25,"lastSyncTime":26,"discoverSource":27},70681,"turbolinks","turbolinks\u002Fturbolinks","Turbolinks makes navigating your web application faster",null,"TypeScript",12594,610,1,71,0,3,43.36,"MIT License",true,false,"master",[],"2026-06-12 02:02:42","# Turbolinks is no longer under active development\n\nPlease note that Turbolinks is no longer under active development. It has been superseded by a new framework called [Turbo](https:\u002F\u002Fgithub.com\u002Fhotwired\u002Fturbo), which is part of the [Hotwire](https:\u002F\u002Fhotwire.dev) umbrella.\n\n# Turbolinks\n\n**Turbolinks® makes navigating your web application faster.** Get the performance benefits of a single-page application without the added complexity of a client-side JavaScript framework. Use HTML to render your views on the server side and link to pages as usual. When you follow a link, Turbolinks automatically fetches the page, swaps in its `\u003Cbody>`, and merges its `\u003Chead>`, all without incurring the cost of a full page load.\n\n![Turbolinks](https:\u002F\u002Fs3.amazonaws.com\u002Fturbolinks-docs\u002Fimages\u002Fturbolinks.gif)\n\n## Features\n\n- **Optimizes navigation automatically.** No need to annotate links or specify which parts of the page should change.\n- **No server-side cooperation necessary.** Respond with full HTML pages, not partial page fragments or JSON.\n- **Respects the web.** The Back and Reload buttons work just as you’d expect. Search engine-friendly by design.\n- **Supports mobile apps.** Adapters for [iOS](https:\u002F\u002Fgithub.com\u002Fturbolinks\u002Fturbolinks-ios) and [Android](https:\u002F\u002Fgithub.com\u002Fturbolinks\u002Fturbolinks-android) let you build hybrid applications using native navigation controls.\n\n## Supported Browsers\n\nTurbolinks works in all modern desktop and mobile browsers. It depends on the [HTML5 History API](http:\u002F\u002Fcaniuse.com\u002F#search=pushState) and [Window.requestAnimationFrame](http:\u002F\u002Fcaniuse.com\u002F#search=requestAnimationFrame). In unsupported browsers, Turbolinks gracefully degrades to standard navigation.\n\n## Installation\n\nTurbolinks automatically initializes itself when loaded via a standalone `\u003Cscript>` tag or a traditional concatenated JavaScript bundle. If you load Turbolinks as a CommonJS or AMD module, first require the module, then call the provided `start()` function.\n\n### Installation Using Ruby on Rails\n\nYour Ruby on Rails application can use the [`turbolinks` RubyGem](https:\u002F\u002Fgithub.com\u002Fturbolinks\u002Fturbolinks-rails) to install Turbolinks. This gem contains a Rails engine which integrates seamlessly with the Rails asset pipeline.\n\n1. Add the `turbolinks` gem, version 5, to your Gemfile: `gem 'turbolinks', '~> 5.2.0'`\n2. Run `bundle install`.\n3. Add `\u002F\u002F= require turbolinks` to your JavaScript manifest file (usually found at `app\u002Fassets\u002Fjavascripts\u002Fapplication.js`).\n\nThe gem also provides server-side support for Turbolinks redirection, which can be used without the asset pipeline.\n\n### Installation Using npm\n\nYour application can use the [`turbolinks` npm package](https:\u002F\u002Fwww.npmjs.com\u002Fpackage\u002Fturbolinks) to install Turbolinks as a module for build tools like [webpack](http:\u002F\u002Fwebpack.github.io\u002F).\n\n1. Add the `turbolinks` package to your application: `npm install --save turbolinks`.\n2. Require and start Turbolinks in your JavaScript bundle:\n\n    ```js\n    var Turbolinks = require(\"turbolinks\")\n    Turbolinks.start()\n    ```\nThe npm package alone does not provide server-side support for Turbolinks redirection. See [Following Redirects](#following-redirects) for details on adding support.\n\n#### Table of Contents\n\n[Navigating with Turbolinks](#navigating-with-turbolinks)\n- [Each Navigation is a Visit](#each-navigation-is-a-visit)\n- [Application Visits](#application-visits)\n- [Restoration Visits](#restoration-visits)\n- [Canceling Visits Before They Start](#canceling-visits-before-they-start)\n- [Disabling Turbolinks on Specific Links](#disabling-turbolinks-on-specific-links)\n\n[Building Your Turbolinks Application](#building-your-turbolinks-application)\n- [Working with Script Elements](#working-with-script-elements)\n  - [Loading Your Application’s JavaScript Bundle](#loading-your-applications-javascript-bundle)\n- [Understanding Caching](#understanding-caching)\n  - [Preparing the Page to be Cached](#preparing-the-page-to-be-cached)\n  - [Detecting When a Preview is Visible](#detecting-when-a-preview-is-visible)\n  - [Opting Out of Caching](#opting-out-of-caching)\n- [Installing JavaScript Behavior](#installing-javascript-behavior)\n  - [Observing Navigation Events](#observing-navigation-events)\n  - [Attaching Behavior With Stimulus](#attaching-behavior-with-stimulus)\n- [Making Transformations Idempotent](#making-transformations-idempotent)\n- [Persisting Elements Across Page Loads](#persisting-elements-across-page-loads)\n\n[Advanced Usage](#advanced-usage)\n- [Displaying Progress](#displaying-progress)\n- [Reloading When Assets Change](#reloading-when-assets-change)\n- [Ensuring Specific Pages Trigger a Full Reload](#ensuring-specific-pages-trigger-a-full-reload)\n- [Setting a Root Location](#setting-a-root-location)\n- [Following Redirects](#following-redirects)\n- [Redirecting After a Form Submission](#redirecting-after-a-form-submission)\n- [Setting Custom HTTP Headers](#setting-custom-http-headers)\n\n[API Reference](#api-reference)\n- [Turbolinks.visit](#turbolinksvisit)\n- [Turbolinks.clearCache](#turbolinksclearcache)\n- [Turbolinks.setProgressBarDelay](#turbolinkssetprogressbardelay)\n- [Turbolinks.supported](#turbolinkssupported)\n- [Full List of Events](#full-list-of-events)\n\n[Contributing to Turbolinks](#contributing-to-turbolinks)\n- [Building From Source](#building-from-source)\n- [Running Tests](#running-tests)\n\n# Navigating with Turbolinks\n\nTurbolinks intercepts all clicks on `\u003Ca href>` links to the same domain. When you click an eligible link, Turbolinks prevents the browser from following it. Instead, Turbolinks changes the browser’s URL using the [History API](https:\u002F\u002Fdeveloper.mozilla.org\u002Fen-US\u002Fdocs\u002FWeb\u002FAPI\u002FHistory), requests the new page using [`XMLHttpRequest`](https:\u002F\u002Fdeveloper.mozilla.org\u002Fen-US\u002Fdocs\u002FWeb\u002FAPI\u002FXMLHttpRequest), and then renders the HTML response.\n\nDuring rendering, Turbolinks replaces the current `\u003Cbody>` element outright and merges the contents of the `\u003Chead>` element. The JavaScript `window` and `document` objects, and the HTML `\u003Chtml>` element, persist from one rendering to the next.\n\n## Each Navigation is a Visit\n\nTurbolinks models navigation as a *visit* to a *location* (URL) with an *action*.\n\nVisits represent the entire navigation lifecycle from click to render. That includes changing browser history, issuing the network request, restoring a copy of the page from cache, rendering the final response, and updating the scroll position.\n\nThere are two types of visit: an _application visit_, which has an action of _advance_ or _replace_, and a _restoration visit_, which has an action of _restore_.\n\n## Application Visits\n\nApplication visits are initiated by clicking a Turbolinks-enabled link, or programmatically by calling [`Turbolinks.visit(location)`](#turbolinksvisit).\n\nAn application visit always issues a network request. When the response arrives, Turbolinks renders its HTML and completes the visit.\n\nIf possible, Turbolinks will render a preview of the page from cache immediately after the visit starts. This improves the perceived speed of frequent navigation between the same pages.\n\nIf the visit’s location includes an anchor, Turbolinks will attempt to scroll to the anchored element. Otherwise, it will scroll to the top of the page.\n\nApplication visits result in a change to the browser’s history; the visit’s _action_ determines how.\n\n![Advance visit action](https:\u002F\u002Fs3.amazonaws.com\u002Fturbolinks-docs\u002Fimages\u002Fadvance.svg)\n\nThe default visit action is _advance_. During an advance visit, Turbolinks pushes a new entry onto the browser’s history stack using [`history.pushState`](https:\u002F\u002Fdeveloper.mozilla.org\u002Fen-US\u002Fdocs\u002FWeb\u002FAPI\u002FHistory\u002FpushState).\n\nApplications using the Turbolinks [iOS adapter](https:\u002F\u002Fgithub.com\u002Fturbolinks\u002Fturbolinks-ios) typically handle advance visits by pushing a new view controller onto the navigation stack. Similarly, applications using the [Android adapter](https:\u002F\u002Fgithub.com\u002Fturbolinks\u002Fturbolinks-android) typically push a new activity onto the back stack.\n\n![Replace visit action](https:\u002F\u002Fs3.amazonaws.com\u002Fturbolinks-docs\u002Fimages\u002Freplace.svg)\n\nYou may wish to visit a location without pushing a new history entry onto the stack. The _replace_ visit action uses [`history.replaceState`](https:\u002F\u002Fdeveloper.mozilla.org\u002Fen-US\u002Fdocs\u002FWeb\u002FAPI\u002FHistory\u002FpushState) to discard the topmost history entry and replace it with the new location.\n\nTo specify that following a link should trigger a replace visit, annotate the link with `data-turbolinks-action=\"replace\"`:\n\n```html\n\u003Ca href=\"\u002Fedit\" data-turbolinks-action=\"replace\">Edit\u003C\u002Fa>\n```\n\nTo programmatically visit a location with the replace action, pass the `action: \"replace\"` option to [`Turbolinks.visit`](#turbolinksvisit):\n\n```js\nTurbolinks.visit(\"\u002Fedit\", { action: \"replace\" })\n```\n\nApplications using the Turbolinks [iOS adapter](https:\u002F\u002Fgithub.com\u002Fturbolinks\u002Fturbolinks-ios) typically handle replace visits by dismissing the topmost view controller and pushing a new view controller onto the navigation stack without animation.\n\n## Restoration Visits\n\nTurbolinks automatically initiates a restoration visit when you navigate with the browser’s Back or Forward buttons. Applications using the [iOS](https:\u002F\u002Fgithub.com\u002Fturbolinks\u002Fturbolinks-ios) or [Android](https:\u002F\u002Fgithub.com\u002Fturbolinks\u002Fturbolinks-android) adapters initiate a restoration visit when moving backward in the navigation stack.\n\n![Restore visit action](https:\u002F\u002Fs3.amazonaws.com\u002Fturbolinks-docs\u002Fimages\u002Frestore.svg)\n\nIf possible, Turbolinks will render a copy of the page from cache without making a request. Otherwise, it will retrieve a fresh copy of the page over the network. See [Understanding Caching](#understanding-caching) for more details.\n\nTurbolinks saves the scroll position of each page before navigating away and automatically returns to this saved position on restoration visits.\n\nRestoration visits have an action of _restore_ and Turbolinks reserves them for internal use. You should not attempt to annotate links or invoke [`Turbolinks.visit`](#turbolinksvisit) with an action of `restore`.\n\n## Canceling Visits Before They Start\n\nApplication visits can be canceled before they start, regardless of whether they were initiated by a link click or a call to [`Turbolinks.visit`](#turbolinksvisit).\n\nListen for the `turbolinks:before-visit` event to be notified when a visit is about to start, and use `event.data.url` (or `$event.originalEvent.data.url`, when using jQuery) to check the visit’s location. Then cancel the visit by calling `event.preventDefault()`.\n\nRestoration visits cannot be canceled and do not fire `turbolinks:before-visit`. Turbolinks issues restoration visits in response to history navigation that has *already taken place*, typically via the browser’s Back or Forward buttons.\n\n## Disabling Turbolinks on Specific Links\n\nTurbolinks can be disabled on a per-link basis by annotating a link or any of its ancestors with `data-turbolinks=\"false\"`.\n\n```html\n\u003Ca href=\"\u002F\" data-turbolinks=\"false\">Disabled\u003C\u002Fa>\n\n\u003Cdiv data-turbolinks=\"false\">\n  \u003Ca href=\"\u002F\">Disabled\u003C\u002Fa>\n\u003C\u002Fdiv>\n```\n\nTo reenable when an ancestor has opted out, use `data-turbolinks=\"true\"`:\n\n```html\n\u003Cdiv data-turbolinks=\"false\">\n  \u003Ca href=\"\u002F\" data-turbolinks=\"true\">Enabled\u003C\u002Fa>\n\u003C\u002Fdiv>\n```\n\nLinks with Turbolinks disabled will be handled normally by the browser.\n\n# Building Your Turbolinks Application\n\nTurbolinks is fast because it doesn’t reload the page when you follow a link. Instead, your application becomes a persistent, long-running process in the browser. This requires you to rethink the way you structure your JavaScript.\n\nIn particular, you can no longer depend on a full page load to reset your environment every time you navigate. The JavaScript `window` and `document` objects retain their state across page changes, and any other objects you leave in memory will stay in memory.\n\nWith awareness and a little extra care, you can design your application to gracefully handle this constraint without tightly coupling it to Turbolinks.\n\n## Working with Script Elements\n\nYour browser automatically loads and evaluates any `\u003Cscript>` elements present on the initial page load.\n\nWhen you navigate to a new page, Turbolinks looks for any `\u003Cscript>` elements in the new page’s `\u003Chead>` which aren’t present on the current page. Then it appends them to the current `\u003Chead>` where they’re loaded and evaluated by the browser. You can use this to load additional JavaScript files on-demand.\n\nTurbolinks evaluates `\u003Cscript>` elements in a page’s `\u003Cbody>` each time it renders the page. You can use inline body scripts to set up per-page JavaScript state or bootstrap client-side models. To install behavior, or to perform more complex operations when the page changes, avoid script elements and use the `turbolinks:load` event instead.\n\nAnnotate `\u003Cscript>` elements with `data-turbolinks-eval=\"false\"` if you do not want Turbolinks to evaluate them after rendering. Note that this annotation will not prevent your browser from evaluating scripts on the initial page load.\n\n### Loading Your Application’s JavaScript Bundle\n\nAlways make sure to load your application’s JavaScript bundle using `\u003Cscript>` elements in the `\u003Chead>` of your document. Otherwise, Turbolinks will reload the bundle with every page change.\n\n```html\n\u003Chead>\n  ...\n  \u003Cscript src=\"\u002Fapplication-cbd3cd4.js\" defer>\u003C\u002Fscript>\n\u003C\u002Fhead>\n```\n\nIf you have traditionally placed application scripts at the end of `\u003Cbody>` for performance reasons, consider using the [`\u003Cscript defer>`](https:\u002F\u002Fdeveloper.mozilla.org\u002Fen-US\u002Fdocs\u002FWeb\u002FHTML\u002FElement\u002Fscript#attr-defer) attribute instead. It has [widespread browser support](https:\u002F\u002Fcaniuse.com\u002F#feat=script-defer) and allows you to keep your scripts in `\u003Chead>` for Turbolinks compatibility.\n\nYou should also consider configuring your asset packaging system to fingerprint each script so it has a new URL when its contents change. Then you can use the `data-turbolinks-track` attribute to force a full page reload when you deploy a new JavaScript bundle. See [Reloading When Assets Change](#reloading-when-assets-change) for information.\n\n## Understanding Caching\n\nTurbolinks maintains a cache of recently visited pages. This cache serves two purposes: to display pages without accessing the network during restoration visits, and to improve perceived performance by showing temporary previews during application visits.\n\nWhen navigating by history (via [Restoration Visits](#restoration-visits)), Turbolinks will restore the page from cache without loading a fresh copy from the network, if possible.\n\nOtherwise, during standard navigation (via [Application Visits](#application-visits)), Turbolinks will immediately restore the page from cache and display it as a preview while simultaneously loading a fresh copy from the network. This gives the illusion of instantaneous page loads for frequently accessed locations.\n\nTurbolinks saves a copy of the current page to its cache just before rendering a new page. Note that Turbolinks copies the page using [`cloneNode(true)`](https:\u002F\u002Fdeveloper.mozilla.org\u002Fen-US\u002Fdocs\u002FWeb\u002FAPI\u002FNode\u002FcloneNode), which means any attached event listeners and associated data are discarded.\n\n### Preparing the Page to be Cached\n\nListen for the `turbolinks:before-cache` event if you need to prepare the document before Turbolinks caches it. You can use this event to reset forms, collapse expanded UI elements, or tear down any third-party widgets so the page is ready to be displayed again.\n\n```js\ndocument.addEventListener(\"turbolinks:before-cache\", function() {\n  \u002F\u002F ...\n})\n```\n\n### Detecting When a Preview is Visible\n\nTurbolinks adds a `data-turbolinks-preview` attribute to the `\u003Chtml>` element when it displays a preview from cache. You can check for the presence of this attribute to selectively enable or disable behavior when a preview is visible.\n\n```js\nif (document.documentElement.hasAttribute(\"data-turbolinks-preview\")) {\n  \u002F\u002F Turbolinks is displaying a preview\n}\n```\n\n### Opting Out of Caching\n\nYou can control caching behavior on a per-page basis by including a `\u003Cmeta name=\"turbolinks-cache-control\">` element in your page’s `\u003Chead>` and declaring a caching directive.\n\nUse the `no-preview` directive to specify that a cached version of the page should not be shown as a preview during an application visit. Pages marked no-preview will only be used for restoration visits.\n\nTo specify that a page should not be cached at all, use the `no-cache` directive. Pages marked no-cache will always be fetched over the network, including during restoration visits.\n\n```html\n\u003Chead>\n  ...\n  \u003Cmeta name=\"turbolinks-cache-control\" content=\"no-cache\">\n\u003C\u002Fhead>\n```\n\nTo completely disable caching in your application, ensure every page contains a no-cache directive.\n\n## Installing JavaScript Behavior\n\nYou may be used to installing JavaScript behavior in response to the `window.onload`, `DOMContentLoaded`, or jQuery `ready` events. With Turbolinks, these events will fire only in response to the initial page load, not after any subsequent page changes. We compare two strategies for connecting JavaScript behavior to the DOM below.\n\n### Observing Navigation Events\n\nTurbolinks triggers a series of events during navigation. The most significant of these is the `turbolinks:load` event, which fires once on the initial page load, and again after every Turbolinks visit.\n\nYou can observe the `turbolinks:load` event in place of `DOMContentLoaded` to set up JavaScript behavior after every page change:\n\n```js\ndocument.addEventListener(\"turbolinks:load\", function() {\n  \u002F\u002F ...\n})\n```\n\nKeep in mind that your application will not always be in a pristine state when this event is fired, and you may need to clean up behavior installed for the previous page.\n\nAlso note that Turbolinks navigation may not be the only source of page updates in your application, so you may wish to move your initialization code into a separate function which you can call from `turbolinks:load` and anywhere else you may change the DOM.\n\nWhen possible, avoid using the `turbolinks:load` event to add other event listeners directly to elements on the page body. Instead, consider using [event delegation](https:\u002F\u002Flearn.jquery.com\u002Fevents\u002Fevent-delegation\u002F) to register event listeners once on `document` or `window`.\n\nSee the [Full List of Events](#full-list-of-events) for more information.\n\n### Attaching Behavior With Stimulus\n\nNew DOM elements can appear on the page at any time by way of Ajax request handlers, WebSocket handlers, or client-side rendering operations, and these elements often need to be initialized as if they came from a fresh page load.\n\nYou can handle all of these updates, including updates from Turbolinks page loads, in a single place with the conventions and lifecycle callbacks provided by Turbolinks’ sister framework, [Stimulus](https:\u002F\u002Fgithub.com\u002Fstimulusjs\u002Fstimulus).\n\nStimulus lets you annotate your HTML with controller, action, and target attributes:\n\n```html\n\u003Cdiv data-controller=\"hello\">\n  \u003Cinput data-target=\"hello.name\" type=\"text\">\n  \u003Cbutton data-action=\"click->hello#greet\">Greet\u003C\u002Fbutton>\n\u003C\u002Fdiv>\n```\n\nImplement a compatible controller and Stimulus connects it automatically:\n\n```js\n\u002F\u002F hello_controller.js\nimport { Controller } from \"stimulus\"\n\nexport default class extends Controller {\n  greet() {\n    console.log(`Hello, ${this.name}!`)\n  }\n\n  get name() {\n    return this.targets.find(\"name\").value\n  }\n}\n```\n\nStimulus connects and disconnects these controllers and their associated event handlers whenever the document changes using the [MutationObserver](https:\u002F\u002Fdeveloper.mozilla.org\u002Fen-US\u002Fdocs\u002FWeb\u002FAPI\u002FMutationObserver) API. As a result, it handles Turbolinks page changes the same way it handles any other type of DOM update.\n\nSee the [Stimulus repository on GitHub](https:\u002F\u002Fgithub.com\u002Fstimulusjs\u002Fstimulus) for more information.\n\n## Making Transformations Idempotent\n\nOften you’ll want to perform client-side transformations to HTML received from the server. For example, you might want to use the browser’s knowledge of the user’s current time zone to group a collection of elements by date.\n\nSuppose you have annotated a set of elements with `data-timestamp` attributes indicating the elements’ creation times in UTC. You have a JavaScript function that queries the document for all such elements, converts the timestamps to local time, and inserts date headers before each element that occurs on a new day.\n\nConsider what happens if you’ve configured this function to run on `turbolinks:load`. When you navigate to the page, your function inserts date headers. Navigate away, and Turbolinks saves a copy of the transformed page to its cache. Now press the Back button—Turbolinks restores the page, fires `turbolinks:load` again, and your function inserts a second set of date headers.\n\nTo avoid this problem, make your transformation function _idempotent_. An idempotent transformation is safe to apply multiple times without changing the result beyond its initial application.\n\nOne technique for making a transformation idempotent is to keep track of whether you’ve already performed it by setting a `data` attribute on each processed element. When Turbolinks restores your page from cache, these attributes will still be present. Detect these attributes in your transformation function to determine which elements have already been processed.\n\nA more robust technique is simply to detect the transformation itself. In the date grouping example above, that means checking for the presence of a date divider before inserting a new one. This approach gracefully handles newly inserted elements that weren’t processed by the original transformation.\n\n## Persisting Elements Across Page Loads\n\nTurbolinks allows you to mark certain elements as _permanent_. Permanent elements persist across page loads, so that any changes you make to those elements do not need to be reapplied after navigation.\n\nConsider a Turbolinks application with a shopping cart. At the top of each page is an icon with the number of items currently in the cart. This counter is updated dynamically with JavaScript as items are added and removed.\n\nNow imagine a user who has navigated to several pages in this application. She adds an item to her cart, then presses the Back button in her browser. Upon navigation, Turbolinks restores the previous page’s state from cache, and the cart item count erroneously changes from 1 to 0.\n\nYou can avoid this problem by marking the counter element as permanent. Designate permanent elements by giving them an HTML `id` and annotating them with `data-turbolinks-permanent`.\n\n```html\n\u003Cdiv id=\"cart-counter\" data-turbolinks-permanent>1 item\u003C\u002Fdiv>\n```\n\nBefore each render, Turbolinks matches all permanent elements by `id` and transfers them from the original page to the new page, preserving their data and event listeners.\n\n# Advanced Usage\n\n## Displaying Progress\n\nDuring Turbolinks navigation, the browser will not display its native progress indicator. Turbolinks installs a CSS-based progress bar to provide feedback while issuing a request.\n\nThe progress bar is enabled by default. It appears automatically for any page that takes longer than 500ms to load. (You can change this delay with the [`Turbolinks.setProgressBarDelay`](#turbolinkssetprogressbardelay) method.)\n\nThe progress bar is a `\u003Cdiv>` element with the class name `turbolinks-progress-bar`. Its default styles appear first in the document and can be overridden by rules that come later.\n\nFor example, the following CSS will result in a thick green progress bar:\n\n```css\n.turbolinks-progress-bar {\n  height: 5px;\n  background-color: green;\n}\n```\n\nTo disable the progress bar entirely, set its `visibility` style to `hidden`:\n\n```css\n.turbolinks-progress-bar {\n  visibility: hidden;\n}\n```\n\n## Reloading When Assets Change\n\nTurbolinks can track the URLs of asset elements in `\u003Chead>` from one page to the next and automatically issue a full reload if they change. This ensures that users always have the latest versions of your application’s scripts and styles.\n\nAnnotate asset elements with `data-turbolinks-track=\"reload\"` and include a version identifier in your asset URLs. The identifier could be a number, a last-modified timestamp, or better, a digest of the asset’s contents, as in the following example.\n\n```html\n\u003Chead>\n  ...\n  \u003Clink rel=\"stylesheet\" href=\"\u002Fapplication-258e88d.css\" data-turbolinks-track=\"reload\">\n  \u003Cscript src=\"\u002Fapplication-cbd3cd4.js\" data-turbolinks-track=\"reload\">\u003C\u002Fscript>\n\u003C\u002Fhead>\n```\n\n## Ensuring Specific Pages Trigger a Full Reload\n\nYou can ensure visits to a certain page will always trigger a full reload by including a `\u003Cmeta name=\"turbolinks-visit-control\">` element in the page’s `\u003Chead>`.\n\n```html\n\u003Chead>\n  ...\n  \u003Cmeta name=\"turbolinks-visit-control\" content=\"reload\">\n\u003C\u002Fhead>\n```\n\nThis setting may be useful as a workaround for third-party JavaScript libraries that don’t interact well with Turbolinks page changes.\n\n## Setting a Root Location\n\nBy default, Turbolinks only loads URLs with the same origin—i.e. the same protocol, domain name, and port—as the current document. A visit to any other URL falls back to a full page load.\n\nIn some cases, you may want to further scope Turbolinks to a path on the same origin. For example, if your Turbolinks application lives at `\u002Fapp`, and the non-Turbolinks help site lives at `\u002Fhelp`, links from the app to the help site shouldn’t use Turbolinks.\n\nInclude a `\u003Cmeta name=\"turbolinks-root\">` element in your pages’ `\u003Chead>` to scope Turbolinks to a particular root location. Turbolinks will only load same-origin URLs that are prefixed with this path.\n\n```html\n\u003Chead>\n  ...\n  \u003Cmeta name=\"turbolinks-root\" content=\"\u002Fapp\">\n\u003C\u002Fhead>\n```\n\n## Following Redirects\n\nWhen you visit location `\u002Fone` and the server redirects you to location `\u002Ftwo`, you expect the browser’s address bar to display the redirected URL.\n\nHowever, Turbolinks makes requests using `XMLHttpRequest`, which transparently follows redirects. There’s no way for Turbolinks to tell whether a request resulted in a redirect without additional cooperation from the server.\n\nTo work around this problem, send the `Turbolinks-Location` header in the final response to a visit that was redirected, and Turbolinks will replace the browser’s topmost history entry with the value you provide.\n\nThe Turbolinks Rails engine sets `Turbolinks-Location` automatically when using `redirect_to` in response to a Turbolinks visit.\n\n## Redirecting After a Form Submission\n\nSubmitting an HTML form to the server and redirecting in response is a common pattern in web applications. Standard form submission is similar to navigation, resulting in a full page load. Using Turbolinks you can improve the performance of form submission without complicating your server-side code.\n\nInstead of submitting forms normally, submit them with XHR. In response to an XHR submit on the server, return JavaScript that performs a [`Turbolinks.visit`](#turbolinksvisit) to be evaluated by the browser.\n\nIf form submission results in a state change on the server that affects cached pages, consider clearing Turbolinks’ cache with [`Turbolinks.clearCache()`](#turbolinksclearcache).\n\nThe Turbolinks Rails engine performs this optimization automatically for non-GET XHR requests that redirect with the `redirect_to` helper.\n\n## Setting Custom HTTP Headers\n\nYou can observe the `turbolinks:request-start` event to set custom headers on Turbolinks requests. Access the request’s XMLHttpRequest object via `event.data.xhr`, then call the [`setRequestHeader`](https:\u002F\u002Fdeveloper.mozilla.org\u002Fen-US\u002Fdocs\u002FWeb\u002FAPI\u002FXMLHttpRequest) method as many times as you wish.\n\nFor example, you might want to include a request ID with every Turbolinks link click and programmatic visit.\n\n```javascript\ndocument.addEventListener(\"turbolinks:request-start\", function(event) {\n  var xhr = event.data.xhr\n  xhr.setRequestHeader(\"X-Request-Id\", \"123...\")\n})\n```\n\n# API Reference\n\n## Turbolinks.visit\n\nUsage:\n```js\nTurbolinks.visit(location)\nTurbolinks.visit(location, { action: action })\n```\n\nPerforms an [Application Visit](#application-visits) to the given _location_ (a string containing a URL or path) with the specified _action_ (a string, either `\"advance\"` or `\"replace\"`).\n\nIf _location_ is a cross-origin URL, or falls outside of the specified root (see [Setting a Root Location](#setting-a-root-location)), or if the value of [`Turbolinks.supported`](#turbolinkssupported) is `false`, Turbolinks performs a full page load by setting `window.location`.\n\nIf _action_ is unspecified, Turbolinks assumes a value of `\"advance\"`.\n\nBefore performing the visit, Turbolinks fires a `turbolinks:before-visit` event on `document`. Your application can listen for this event and cancel the visit with `event.preventDefault()` (see [Canceling Visits Before They Start](#canceling-visits-before-they-start)).\n\n## Turbolinks.clearCache\n\nUsage:\n```js\nTurbolinks.clearCache()\n```\n\nRemoves all entries from the Turbolinks page cache. Call this when state has changed on the server that may affect cached pages.\n\n## Turbolinks.setProgressBarDelay\n\nUsage:\n```js\nTurbolinks.setProgressBarDelay(delayInMilliseconds)\n```\n\nSets the delay after which the [progress bar](#displaying-progress) will appear during navigation, in milliseconds. The progress bar appears after 500ms by default.\n\nNote that this method has no effect when used with the iOS or Android adapters.\n\n## Turbolinks.supported\n\nUsage:\n```js\nif (Turbolinks.supported) {\n  \u002F\u002F ...\n}\n```\n\nDetects whether Turbolinks is supported in the current browser (see [Supported Browsers](#supported-browsers)).\n\n## Full List of Events\n\nTurbolinks emits events that allow you to track the navigation lifecycle and respond to page loading. Except where noted, Turbolinks fires events on the `document` object.  \nNote that when using jQuery, the data on the event must be accessed as `$event.originalEvent.data`.\n\n* `turbolinks:click` fires when you click a Turbolinks-enabled link. The clicked element is the event target. Access the requested location with `event.data.url`. Cancel this event to let the click fall through to the browser as normal navigation.\n\n* `turbolinks:before-visit` fires before visiting a location, except when navigating by history. Access the requested location with `event.data.url`. Cancel this event to prevent navigation.\n\n* `turbolinks:visit` fires immediately after a visit starts.\n\n* `turbolinks:request-start` fires before Turbolinks issues a network request to fetch the page. Access the XMLHttpRequest object with `event.data.xhr`.\n\n* `turbolinks:request-end` fires after the network request completes. Access the XMLHttpRequest object with `event.data.xhr`.\n\n* `turbolinks:before-cache` fires before Turbolinks saves the current page to cache.\n\n* `turbolinks:before-render` fires before rendering the page. Access the new `\u003Cbody>` element with `event.data.newBody`.\n\n* `turbolinks:render` fires after Turbolinks renders the page. This event fires twice during an application visit to a cached location: once after rendering the cached version, and again after rendering the fresh version.\n\n* `turbolinks:load` fires once after the initial page load, and again after every Turbolinks visit. Access visit timing metrics with the `event.data.timing` object.\n\n# Contributing to Turbolinks\n\nTurbolinks is open-source software, freely distributable under the terms of an [MIT-style license](LICENSE). The [source code is hosted on GitHub](https:\u002F\u002Fgithub.com\u002Fturbolinks\u002Fturbolinks).\nDevelopment is sponsored by [Basecamp](https:\u002F\u002Fbasecamp.com\u002F).\n\nWe welcome contributions in the form of bug reports, pull requests, or thoughtful discussions in the [GitHub issue tracker](https:\u002F\u002Fgithub.com\u002Fturbolinks\u002Fturbolinks\u002Fissues).\n\nPlease note that this project is released with a [Contributor Code of Conduct](CONDUCT.md). By participating in this project you agree to abide by its terms.\n\n## Building From Source\n\nTurbolinks is written in [TypeScript](https:\u002F\u002Fwww.typescriptlang.org). To build from source, first make sure you have the [Yarn package manager](https:\u002F\u002Fyarnpkg.com) installed. Then issue the following commands to build the distributable files in `dist\u002F`:\n\n```\n$ yarn install\n$ yarn build\n```\n\nInclude the resulting `dist\u002Fturbolinks.js` file in your application’s JavaScript bundle.\n\n## Running Tests\n\nTurbolinks is tested with the [Intern testing library](https:\u002F\u002Ftheintern.io).\n\nTo run the test suite, follow the instructions for _Building From Source_ above, then run:\n\n```\n$ yarn test\n```\n\nIf you are testing changes to the Turbolinks source, remember to run `yarn build` before each test run. Or, run `yarn watch` to build automatically as you work.\n\n---\n\n© 2019 Basecamp, LLC.\n","Turbolinks 是一个用于加速网页应用导航的工具。它通过在用户点击链接时仅加载页面的 `\u003Cbody>` 部分并合并 `\u003Chead>`，从而避免了全页面刷新，实现了类似单页应用的性能优势，同时保持了服务器端渲染 HTML 的简单性。其核心特点包括自动优化导航、无需服务器端额外支持、兼容标准浏览器行为以及支持移动应用开发。适用于希望提升用户体验但又不想引入复杂前端框架的传统 Web 应用场景。尽管 Turbolinks 已不再积极维护，并被 Turbo 所取代，但它依然为开发者提供了一种简便的方式来改善网页加载速度。",2,"2026-06-11 03:33:36","high_star"]