galileo_seo 3.0.0 icon indicating copy to clipboard operation
galileo_seo: ^3.0.0 copied to clipboard

Helper infrastructure for building SEO-friendly Web backends in Galileo.

seo #

Pub build status

Helpers for building SEO-friendly Web pages in Galileo. The goal of package:galileo_seo is to speed up perceived client page loads, prevent the infamous flash of unstyled content, and other SEO optimizations that can easily become tedious to perform by hand.

Disabling inlining per-element #

Add a data-no-inline attribute to a link or script to prevent inlining it:

<script src="main.dart.js" data-no-inline></script>

inlineAssets #

A response finalizer that can be used in any application to patch HTML responses, including those sent with a templating engine like Jael.

In any text/html response sent down, link and script elements that point to internal resources will have the contents of said file read, and inlined into the HTML page itself.

In this case, "internal resources" refers to a URI without a scheme, i.e. /site.css or foo/bar/baz.js.

import 'package:galileo_framework/galileo_framework.dart';
import 'package:galileo_seo/galileo_seo.dart';
import 'package:galileo_static/galileo_static.dart';
import 'package:file/local.dart';

main() async {
  var app = new Galileo()..lazyParseBodies = true;
  var fs = const LocalFileSystem();
  var http = new GalileoHttp(app);

  app.responseFinalizers.add(inlineAssets(fs.directory('web')));

  app.use(() => throw new GalileoHttpException.notFound());

  var server = await http.startServer('127.0.0.1', 3000);
  print('Listening at http://${server.address.address}:${server.port}');
}

inlineAssetsFromVirtualDirectory #

This function is a simple one; it wraps a VirtualDirectory to patch the way it sends .html files.

Produces the same functionality as inlineAssets.

import 'package:galileo_framework/galileo_framework.dart';
import 'package:galileo_seo/galileo_seo.dart';
import 'package:galileo_static/galileo_static.dart';
import 'package:file/local.dart';

main() async {
  var app = new Galileo()..lazyParseBodies = true;
  var fs = const LocalFileSystem();
  var http = new GalileoHttp(app);

  var vDir = inlineAssets(
    new VirtualDirectory(
      app,
      fs,
      source: fs.directory('web'),
    ),
  );

  app.use(vDir.handleRequest);

  app.use(() => throw new GalileoHttpException.notFound());

  var server = await http.startServer('127.0.0.1', 3000);
  print('Listening at http://${server.address.address}:${server.port}');
}
2
likes
110
pub points
0%
popularity

Publisher

verified publisher icongalileodart.com

Helper infrastructure for building SEO-friendly Web backends in Galileo.

Repository (GitHub)

Documentation

API reference

License

Icon for licenses.MIT (LICENSE)

Dependencies

file, galileo_framework, galileo_static, html, http_parser, path

More

Packages that depend on galileo_seo