platform/packages/seo
thomashii@dukefirehawk.com 1560e147cc Updated min SDK to 2.17
2022-08-13 10:14:43 +08:00
..
example Updated seo 2021-08-20 10:33:49 +08:00
lib Updated seo 2021-08-20 10:33:49 +08:00
test Updated seo 2021-08-20 10:33:49 +08:00
.gitignore Add 'packages/seo/' from commit '43e953044bb7f8eb8fc4c0d11f49e9cd53583e48' 2020-02-15 18:29:02 -05:00
analysis_options.yaml Updated linter 2022-01-04 20:03:52 +08:00
AUTHORS.md Merged from sdk-2.12.x_nnbd 2021-06-20 20:37:20 +08:00
CHANGELOG.md Updated to SDK 2.16.x 2022-04-23 12:21:39 +08:00
LICENSE Updated linter 2022-01-04 20:03:52 +08:00
melos_angel3_seo.iml Added melos 2022-03-19 09:37:28 +08:00
pubspec.yaml Updated min SDK to 2.17 2022-08-13 10:14:43 +08:00
README.md Updated to lints linter 2022-01-05 12:03:02 +08:00

Angel3 SEO

Pub Version (including pre-releases) Null Safety Gitter License

Helpers for building SEO-friendly Web pages in Angel. The goal of package:angel3_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 Jael3.

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:angel3_framework/angel3_framework.dart';
import 'package:angel3_seo/angel3_seo.dart';
import 'package:angel3_static/angel3_static.dart';
import 'package:file/local.dart';

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

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

  app.use(() => throw 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:angel3_framework/angel3_framework.dart';
import 'package:angel3_seo/angel3_seo.dart';
import 'package:angel3_static/angel3_static.dart';
import 'package:file/local.dart';

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

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

  app.use(vDir.handleRequest);

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

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