Cache images: max-age + last-modified.
This commit is contained in:
parent
2d65f0aecb
commit
cd6bfd23ea
|
@ -2,6 +2,7 @@ var camp = require('camp').start({
|
|||
port: process.env.PORT||+process.argv[2]||80
|
||||
});
|
||||
var badge = require('./badge.js');
|
||||
var serverStartTime = new Date((new Date()).toGMTString());
|
||||
|
||||
// Escapes `t` using the format specified in
|
||||
// <https://github.com/espadrine/gh-badges/issues/12#issuecomment-31518129>
|
||||
|
@ -23,6 +24,14 @@ camp.route(/^\/(([^-]|--)+)-(([^-]|--)+)-(([^-]|--)+).svg$/,
|
|||
var status = escapeFormat(match[3]);
|
||||
var color = escapeFormat(match[5]);
|
||||
ask.res.setHeader('Content-Type', 'image/svg+xml');
|
||||
var cacheDuration = (3600*24*1)|0; // 1 day.
|
||||
ask.res.setHeader('Cache-Control', 'public, max-age=' + cacheDuration);
|
||||
if (+(new Date(ask.req.headers['if-modified-since'])) >= +serverStartTime) {
|
||||
ask.res.statusCode = 304;
|
||||
ask.res.end(); // not modified.
|
||||
return;
|
||||
}
|
||||
ask.res.setHeader('Last-Modified', serverStartTime.toGMTString());
|
||||
try {
|
||||
var badgeData = {text: [subject, status]};
|
||||
if (sixHex(color)) {
|
||||
|
|
|
@ -12,8 +12,8 @@ a.photo>img { padding: 2px; border: 1px solid grey; }
|
|||
ul { text-align: left; margin-left: 25%; }
|
||||
</style>
|
||||
|
||||
<img src='http://gh-badges.herokuapp.com/badge-on!-brightgreen.svg'>
|
||||
<img src='http://gh-badges.herokuapp.com/license-CC0-red.svg'>
|
||||
<img src='/badge-on!-brightgreen.svg'>
|
||||
<img src='/license-CC0-red.svg'>
|
||||
|
||||
<p>
|
||||
Ever wanted to have your own GitHub badges? <br/>
|
||||
|
@ -24,7 +24,7 @@ Maybe you simply love SVG. <br/>
|
|||
Maybe you fancy a format that uses less than half the bandwidth.
|
||||
</p>
|
||||
|
||||
<img src='http://gh-badges.herokuapp.com/happy-hacking%20%E2%98%BA-yellow.svg'>
|
||||
<img src='/happy-hacking%20%E2%98%BA-yellow.svg'>
|
||||
|
||||
<p>
|
||||
As for me, I wanted a format that people can reuse and hack on. <br/>
|
||||
|
@ -32,7 +32,7 @@ I wanted a service for everyone. <br/>
|
|||
I made the GitHub Badge Service.
|
||||
</p>
|
||||
|
||||
<img src='http://gh-badges.herokuapp.com/download-.5K-blue.svg'>
|
||||
<img src='/download-.5K-blue.svg'>
|
||||
|
||||
<p>
|
||||
Here's how it works. <br/>
|
||||
|
@ -43,15 +43,15 @@ Use an underscore <code>_</code> if you want a space. Or, you know, use a space.
|
|||
</p>
|
||||
|
||||
<p> Colors: </p>
|
||||
<img src='http://gh-badges.herokuapp.com/color-brightgreen-brightgreen.svg'>
|
||||
<img src='http://gh-badges.herokuapp.com/color-green-green.svg'>
|
||||
<img src='http://gh-badges.herokuapp.com/color-yellowgreen-yellowgreen.svg'>
|
||||
<img src='http://gh-badges.herokuapp.com/color-yellow-yellow.svg'>
|
||||
<img src='http://gh-badges.herokuapp.com/color-orange-orange.svg'>
|
||||
<img src='http://gh-badges.herokuapp.com/color-red-red.svg'>
|
||||
<img src='http://gh-badges.herokuapp.com/color-lightgrey-lightgrey.svg'>
|
||||
<img src='http://gh-badges.herokuapp.com/color-blue-blue.svg'>
|
||||
<img src='http://gh-badges.herokuapp.com/color-ff69b4-ff69b4.svg'>
|
||||
<img src='/color-brightgreen-brightgreen.svg'>
|
||||
<img src='/color-green-green.svg'>
|
||||
<img src='/color-yellowgreen-yellowgreen.svg'>
|
||||
<img src='/color-yellow-yellow.svg'>
|
||||
<img src='/color-orange-orange.svg'>
|
||||
<img src='/color-red-red.svg'>
|
||||
<img src='/color-lightgrey-lightgrey.svg'>
|
||||
<img src='/color-blue-blue.svg'>
|
||||
<img src='/color-ff69b4-ff69b4.svg'>
|
||||
|
||||
<h2> Like This? </h2>
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user