Skip to content

Instantly share code, notes, and snippets.

@gre
Last active November 12, 2021 15:20
Show Gist options
  • Save gre/9364718 to your computer and use it in GitHub Desktop.
Save gre/9364718 to your computer and use it in GitHub Desktop.
Boilerplate of a JS1K submission + JSCrush & uglify tools

JS1K Boilerplate

Build tools

Install tools

npm install

Then run it with:

npm run build

It will give you some stats:

    1008 crushed.js
    1704 minified.js
    5739 source.js

Suggestion


DWTFYW license 2014 - @greweb

<!doctype html>
<html>
<head>
<title>JS1k, [COMPO] demo submission [ID]</title>
<meta charset="utf-8" />
<style>
html, body { margin: 0; padding: 0; border: 0; }
#c { display: block; } /* kill scrollbars from hell */
</style>
</head>
<body>
<canvas id="c"></canvas>
<script>
var a = document.getElementsByTagName('canvas')[0];
var b = document.body;
var d = function(e){ return function(){ e.parentNode.removeChild(e); }; }(a);
// unprefix some popular vendor prefixed things (but stick to their original name)
var AudioContext =
window.AudioContext ||
window.webkitAudioContext;
var requestAnimationFrame =
window.requestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(f){ setTimeout(f, 1000/30); };
// fix bug in safari: http://qfox.nl/weblog/218
document.body.clientWidth;
// auto resize (original) canvas. call `onresize(w,h) to limit the size of the canvas
(window.onorientationchange = window.onresize = function(a){
var mw = false;
var mh = false;
var max = Math.max;
return function(w,h){
if (arguments.length === 2) {
mw = w;
mh = h;
}
a.style.width = (a.width = max(mw, innerWidth)) + 'px';
a.style.height = (a.height = max(mh, innerHeight)) + 'px';
};
}(a))();
var c = a.getContext('2d');
</script>
<script type="text/javascript" src="source.js"></script>
</body>
</html>
{
"name": "js1k_template",
"version": "0.0.0",
"devDependencies": {
"uglify-js": "2.4.x",
"jscrush": "0.0.0"
},
"scripts": {
"build": "cat source.js | uglifyjs -c unused=false | tee minified.js | jscrush > crushed.js && wc -c *.js"
}
}
// Template of source code
// Following code is just a suggestion
t = 0;
L = function () {
setTimeout(L, 9);
c.fillRect(0, 10, t++, 50);
}
L();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment