Just getting started with turbolinks and they claim it can be used without a client-side javascript framework, I made a bootstrap 4 template and tried installing it.
Downloaded the .js from repo file and included in the head:
<script type="text/javascript" src="js/turbolinks.js"></script>
And just before the closing body tag:
<script>
Turbolinks.start()
</script>
Console debug don't give any errors, js is loaded but the whole page is loaded every time I visit a new link.
Tried to add var Turbolinks = require("turbolinks")
in webserver but I get error.
Server.js
//jshint esversion:6
const express = require("express")
const app = express();
var Turbolinks = require("turbolinks")
app.get("/", function(req, res){
res.sendFile( __dirname + "/public/" + "index.html" );
});
app.use(express.static(__dirname + '/public'));
app.listen(3000, function(){
console.log("Server started on port 3000")
});
index.html
<!doctype html>
<html lang="en">
<head>
<link rel='icon' href='favicon.ico' type='image/x-icon' />
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/style.css" type="text/css">
<link href="https://fonts.googleapis.com/css?family=IM+Fell+English|Lato:400,700&display=swap" rel="stylesheet">
<script src="https://kit.fontawesome.com/e5f3028323.js" crossorigin="anonymous"></script>
<script type="text/javascript" src="js/turbolinks.js"></script>
<title>App</title>
</head>
<body>
<section class="navbar sticky-top justify-content-between">
<span></span>
<div class="p-2 bd-highlight">CW App</div>
<button type="button" class="btn btn-nav">
<i class="fas fa-ellipsis-h"></i>
</button>
</section>
<div class="nav-bg"></div>
<section class="container">
<div class="row">
<div class="col d-flex justify-content-center cerca">
<form class="form-inline">
<input class="form-control form-control-search" type="search" placeholder="Search" aria-label="Search">
<button class="btn-cerca my-2 my-sm-0" type="submit"><i class="fa fa-search"></i></button>
</form>
</div>
</div>
</section>
<section class="container" data-turbolinks-permanent>
<div class="row">
<div class="col">
<div class="list-group list-button mx-auto">
<button class="list-group-item d-flex justify-content-between align-items-center">
<span><img class="menu-icon" src="img/icons-menu/rulebook.png">Rulebook</span>
<span class="list-arrow">›</span>
</button>
<button class="list-group-item d-flex justify-content-between align-items-center">
<span><img class="menu-icon" src="img/icons-menu/factions.png">Factions</span>
<span class="list-arrow">›</span>
</button>
<button class="list-group-item d-flex justify-content-between align-items-center">
<span><img class="menu-icon" src="img/icons-menu/neutrals.png">Neutrals</span>
<span class="list-arrow">›</span>
</button>
<button class="list-group-item d-flex justify-content-between align-items-center">
<span><img class="menu-icon" src="img/icons-menu/maps.png">Maps</span>
<span class="list-arrow">›</span>
</button>
<button class="list-group-item d-flex justify-content-between align-items-center">
<span><img class="menu-icon" src="img/icons-menu/dice.png">Dice Roll</span>
<span class="list-arrow">›</span>
</button>
<button class="list-group-item d-flex justify-content-between align-items-center">
<span><img class="menu-icon" src="img/icons-menu/randomizer.png">Game Randomizer</span>
<span class="list-arrow">›</span>
</button>
<button class="list-group-item d-flex justify-content-between align-items-center">
<span><img class="menu-icon" src="img/icons-menu/doom.png">Doom & Ritual Track</span>
<span class="list-arrow">›</span>
</button>
<button class="list-group-item d-flex justify-content-between align-items-center" onclick="window.location.href = './timer.html';">
<span><img class="menu-icon" src="img/icons-menu/timer.png">Timer</span>
<span class="list-arrow">›</span>
</button>
<button class="list-group-item d-flex justify-content-between align-items-center">
<span><img class="menu-icon" src="img/icons-menu/music.png">Background Music</span>
<span class="list-arrow">›</span>
</button>
</div>
</div>
</div>
</section>
<!-- JavaScript -->
<script type="text/javascript" src="js/bootstrap-native-v4.min.js"></script>
<script type="text/javascript" src="js/script.js"></script>
<script>
Turbolinks.start()
</script>
</body>
</html>
The documentation for TurboLinks says:
Turbolinks intercepts all clicks on
<a href>
links to the same domain.
… but your HTML doesn't have any of those.
You have some <button>
elements, which I guess you might have some JavaScript to make them act like links, but TurboLinks isn't going to pick them up.
It does have a mechanism for manually triggering TurboLinks, but you'd be better off using real links instead of buttons and JavaScript.