platform/packages/seo
2021-06-14 11:52:58 +08:00
..
example Add 'packages/seo/' from commit '43e953044bb7f8eb8fc4c0d11f49e9cd53583e48' 2020-02-15 18:29:02 -05:00
lib Add 'packages/seo/' from commit '43e953044bb7f8eb8fc4c0d11f49e9cd53583e48' 2020-02-15 18:29:02 -05:00
test Fixed test errors 2021-02-21 10:47:23 +08:00
.gitignore Add 'packages/seo/' from commit '43e953044bb7f8eb8fc4c0d11f49e9cd53583e48' 2020-02-15 18:29:02 -05:00
.travis.yml Add 'packages/seo/' from commit '43e953044bb7f8eb8fc4c0d11f49e9cd53583e48' 2020-02-15 18:29:02 -05:00
analysis_options.yaml Add 'packages/seo/' from commit '43e953044bb7f8eb8fc4c0d11f49e9cd53583e48' 2020-02-15 18:29:02 -05:00
CHANGELOG.md Add 'packages/seo/' from commit '43e953044bb7f8eb8fc4c0d11f49e9cd53583e48' 2020-02-15 18:29:02 -05:00
LICENSE Updated license 2021-06-14 11:52:58 +08:00
pubspec.yaml Updated dart requirements to 2.10 2021-02-14 13:22:25 +08:00
README.md Add 'packages/seo/' from commit '43e953044bb7f8eb8fc4c0d11f49e9cd53583e48' 2020-02-15 18:29:02 -05:00

seo

Pub build status

Helpers for building SEO-friendly Web pages in Angel. The goal of package:angel_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:angel_framework/angel_framework.dart';
import 'package:angel_seo/angel_seo.dart';
import 'package:angel_static/angel_static.dart';
import 'package:file/local.dart';

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

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

  app.use(() => throw new AngelHttpException.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:angel_framework/angel_framework.dart';
import 'package:angel_seo/angel_seo.dart';
import 'package:angel_static/angel_static.dart';
import 'package:file/local.dart';

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

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

  app.use(vDir.handleRequest);

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

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