# Start a PHP server from a directory, optionally specifying the port
# (Requires PHP 5.4.0+.)
function phpserver() {
local port="${1:-4000}"
local ip=$(ipconfig getifaddr en4) #ensure correct interface with ifconfig
sleep 1 && open "http://${ip}:${port}/" &
php -S "${ip}:${port}"
}
@function em($target, $context: $font-size) {
@return ($target / $context) * 1em;
}
@function rem($target, $context: $font-size) {
@return ($target / $context) * 1rem;
}
@function lh($target, $context: $font-size) {
@return $target / $context;
}
// Global variables set in _config.scss: $font-size: 16px;
// Example
.example-selector {
font-size: em(22px);
line-height: lh(50px, 22px);
margin-bottom: em(20px, 22px);
}
@function cw($columns, $context: $font-size) { @return ($columns * em($width-column, $context)) + (($columns - 1) * em($space-s, $context)); } // Global variables set in _config.scss: $font-size: 16px; $space-s: 20px; $width-column: 60px;
// Examples .example-selector { width: cw(8); } .example-heading-selector { font-size: em(22px); max-width: cw(6, 22px); }
@mixin bp($point) {
@media (max-width: ($point + em(2 * $space-s))) {
@content;
}
}
// Global variables set in _config.scss: $space-s: 20px;
// Example
.example-selector {
position: absolute;
@include bp(cw(6)) {
position: relative;
}
}
<button class="p1">Buy now</button>
<button class="p2">Not so important button</button>
<button class="p2 a1">Not so important button variation</button>
Tried a few different approaches: Angular, JSON api with Mustache templates
Settled on server side rendering of page templates progressively enhanced with JavaScript because Colony is all about the content
Twitter found it cut load times to 1/5th:
https://blog.twitter.com/2012/improving-performance-on-twittercom
URLs point directly to the right content, Paul Irish talked about the effect of Imgur using JSON APIs on their (slow) page speed in Fluent 2014 keynote:
// Example markup
<div class="asset-bucket" data-behavior="slider">
<h2 class="heading-p4">Video & Audio</h2>
<div class="items assets">
<div class="item-wrapper">
<a href="/pages/companion-explore-vod.php" class="item asset" data-behavior="asset">
...
</a>
// asset.js: In asset behavior, it's possible to hit the paywall instead of getting the asset
$.publish('/paywall/hit', data);
// paywall.js: In paywall behavior we subscribe/handle the topic, call displayPaywall
function handleTopics() {
$.subscribe('/paywall/hit', function(e, data) {
displayPaywall(data);
});
}