Giter Site home page Giter Site logo

hexo-filter-crossorigin's Introduction

hexo-filter-crossorigin

status npm version

Append crossorigin attribute to HTML elements (<img>, <video>, etc).

Why

See https://developers.google.com/web/tools/workbox/guides/handle-third-party-requests#remember_to_opt-in_to_cors_mod.

UPDATE (2019-11): To cache thrid part resouces which have CORS configured correctly, you can also write your service workers script like this (notice fetchOptions field):

workbox.routing.registerRoute(
  new RegExp("https?://cdn.jsdelivr.net/"),
  new workbox.strategies.CacheFirst({
    cacheName: "static-resources",
    fetchOptions: {
      mode: "cors",
      credentials: "omit"
    },
    plugins: [
      new workbox.expiration.Plugin({
        maxAgeSeconds: oneYear
      })
    ]
  })
);

Config

# _config.yml

filter_crossorigin:
  - name: img
    crossorigin: true
    domains:
      - unpkg.com
    attrs:
      - src
  • name: selectors (such as img.lazyload or link[rel="stylesheet"]).
  • crossorigin: true (alias of anonymous) | false | anonymous | use-credentials.
  • domains: optional. If not provided, all elements that match tag name will be affected.
  • attrs: optional. Tag attributes to match domains. Default to src, data-src, href.

hexo-filter-crossorigin's People

Contributors

dependabot[bot] avatar giuem avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

hexo-filter-crossorigin's Issues

Shouldn't process all <link> elements

https://runkit.com/sukkaw/5dd424854e2cde0013e84050

const appendAttr = require('hexo-filter-crossorigin/lib/appendAttr.js');
require('chai').should();

const tags = [
    { "name": "link", "crossorigin": true }
];

const html_1 = '<link rel="preconnect" href="//cdn.jsdelivr.net">';
const html_2 = '<link href="https://blog.skk.moe/" rel="canonical">';

const expected_1 = '<link rel="preconnect" href="//cdn.jsdelivr.net" crossorigin="anonymous">';
const expected_2 = html_2;

appendAttr.default(html_1, tags).should.eql(expected_1);
appendAttr.default(html_2, tags).should.eql(expected_2);
AssertionError: expected '<link href="https://blog.skk.moe/" rel="canonical" crossorigin="anonymous">' to deeply equal '<link href="https://blog.skk.moe/" rel="canonical">'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.