Skip to content

Instantly share code, notes, and snippets.

View developit's full-sized avatar
🦊
write, the codes

Jason Miller developit

🦊
write, the codes
View GitHub Profile
@idudinov
idudinov / prerenderPlugin.js
Last active June 16, 2021 14:56
PrerenderPlugin for HtmlWebpackPlugin – Pre-renders html during Webpack build phase
const HtmlWebpackPlugin = require('html-webpack-plugin');
const jsdom = require('jsdom');
/** @typedef {import("webpack/lib/Compiler.js")} WebpackCompiler */
/** @typedef {import("webpack/lib/Compilation.js")} WebpackCompilation */
/** @typedef {(import 'jsdom').ResourceLoaderConstructorOptions} ResourceLoaderConstructorOptions */
class PrerenderHtmlPlugin {
constructor(options) {
this._options = options || { };
@developit
developit / array-indexed property access benchmark.js
Created September 16, 2018 00:56
deoptigate -- node --allow-natives-syntax *.js
const { performance } = require('perf_hooks');
const h1 = (tag, props, children) => ({ tag, props, children })
const h2 = (tag, props, children) => ({ tag, props, children })
function serializeProps(props) {
let out = '';
for (let i in props) out += ` ${i}="${props[i]}"`;
return out;
}
@ebidel
ebidel / download_chrome41.js
Last active May 28, 2026 01:45
For when you need to test your site in Google Search (Chrome 41).
/**
* Copyright 2018 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@davidgilbertson
davidgilbertson / http2.js
Last active February 22, 2025 22:22
HTTP2 server with compression and caching
const http2 = require('http2');
const fs = require('fs');
const path = require('path');
const zlib = require('zlib');
const brotli = require('brotli'); // npm package
const PORT = 3032;
const BROTLI_QUALITY = 11; // slow, but we're caching so who cares
const STATIC_DIRECTORY = path.resolve(__dirname, '../dist/');
const cache = {};
@treshugart
treshugart / README.md
Last active May 6, 2024 05:03
HMR for generic web components

Generic web component HMR

I'm messing around with a generic way to do hot-module-replacement with generic web components whether they be vanilla, or done in a framework like Polymer or Skate.

The idea is that you call hmr(customElementConstructor) in your module files and it will set up the proper hooks.

The const filename should be inserted at build time so that it can remember the original localName of the component for the module.

WTF is "x-layout", "Layout" and "filename"

@marvinhagemeister
marvinhagemeister / *valoo.md
Last active July 14, 2018 20:20 — forked from developit/*valoo.md
🐻 Valoo: just the bare necessities of state management. 150b / 120b. https://npm.im/valoo

🐻 valoo

just the bare necessities of state management.

Usage

Hotlink it from https://unpkg.com/valoo.

See Interactive Codepen Demo.

@developit
developit / *valoo.md
Last active July 25, 2026 07:42
🐻 Valoo: just the bare necessities of state management. 150b / 120b. https://npm.im/valoo

🐻 valoo

just the bare necessities of state management.

Usage

Hotlink it from https://unpkg.com/valoo.

See Interactive Codepen Demo.

@searls
searls / router-hack.js
Last active June 17, 2018 16:11
override preact-router so we can synchronously change the route & trigger a render
/*
* override preact-router so we can synchronously change the route & trigger a render
* reason for doing this: often a UI action triggers an XHR which in turn will determine
* where the user needs to go next (it's a flashcard game, so whether they got it right or wrong
* will determine whether their session has concluded, whether to draw the next card, and so on)
* as a result we have a lot of action logic that wants to in one-fell-swoop programmatically route
* the user to a different component and also update the properties passed to the components by
* re-rendering (one big top-level render function, all state just passed by props, no stateful components)
*
* The practical effect of this change versus the built-in router was that it cuts the number of
@developit
developit / preact-unrecycle.js
Last active January 28, 2019 04:27
preact-unrecycle.js
/** Usage:
* const MyView = unrecycle(props => {
* // this is normally a no-go and creates leaking styles, but it won't with unrecycle():
* <input ref={ c => c && c.style.background='red' } />
* })
*/
export default function unrecycle(Component) {
return function Unrecycle(props, context) {
this.componentWillUnmount = dontRecycle;
return Component.call(this, props, context);
@justinfagnani
justinfagnani / README.md
Last active April 21, 2022 08:45
Inline JavaScript Modules Definitions

Inline JavaScript Module Definitions

Motivation

Domenic's blöcks proposal outlines a way to conveniently define functions that run in another worker/worklet as an inline, non-capturing scope, function body.

Blöcks as proposed have a few open questions and lack a few features that could generalize them to more use cases and with more practical ergonomics.

  • Blöcks don't allow static imports, which makes it harder for them to import neccessary library code. They must rely on dynamic import, which is somewhat more difficult to statically analyzer.