Permalink
Browse files

* Make url_for subdomain serving be through an explicit template tag …

…parameter, so we don't use random subdomains (as they do not provide performance improvements).
  • Loading branch information...
1 parent 132ef78 commit 689973137a341668ef45d4fb153164a0a22d5ee3 @dannyakakong committed Jan 11, 2014
Showing with 22 additions and 15 deletions.
  1. +17 −8 ext/flask/helpers.py
  2. +0 −2 init.py
  3. +3 −3 templates/base/structure.html
  4. +2 −2 templates/index.html
View
@@ -290,6 +290,9 @@ def external_url_handler(error, endpoint, **values):
'the SERVER_NAME config variable.')
external = values.pop('_external', True)
+ # use a subdomain?
+ subdomain = values.pop('subdomain', None)
+
anchor = values.pop('_anchor', None)
method = values.pop('_method', None)
scheme = values.pop('_scheme', None)
@@ -314,21 +317,27 @@ def external_url_handler(error, endpoint, **values):
if anchor is not None:
rv += '#' + url_quote(anchor)
+
# make live environment modifications
- if not current_app.config['DEBUG'] or current_app.config['LIVE']:
- # use minified files
+ is_live = ('LIVE' in current_app.config) and current_app.config['LIVE']
+
+ if not current_app.config['DEBUG'] or is_live:
+ # use minified files?
if current_app.config['STATIC_MINIFY_FILENAME']:
for key, value in current_app.config['STATIC_MINIFY_FILENAME'].items():
rv = rv.replace(key, value)
- # CDN
- if not current_app.config['DEBUG'] and current_app.config['STATIC_CDN']:
- from random import choice
+ # use a subdomain?
+ if subdomain:
+ if current_app.config['LIVE'] and current_app.config['DEBUG']:
+ url = current_app.config['LIVE'][:-1]
+ else:
+ url = request.url[:-1]
- rv = request.url.replace(
+ rv = url.replace(
'://',
- '://{0}.'.format(choice(current_app.config['STATIC_CDN'])),
- )
+ '://{0}.'.format(subdomain),
+ ) + rv
return rv
View
@@ -15,8 +15,6 @@
app = Flask(__name__)
-app.config["LIVE"] = True
-app.config["STATIC_CDN"] = ["s0", "s1", "s2", "s3", "s4", "s5"]
app.config["STATIC_MINIFY_FILENAME"] = {
".js": ".min.js",
".css": ".min.css",
@@ -8,7 +8,7 @@
<meta name="viewport" content="width=device-width" />
<meta name="google-site-verification" content="beTdAhx0raFrnhbZNxbSm063fSA6hDg5m81DHc9exU0" />
- <link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}" />
+ <link rel="stylesheet" href="{{ url_for('static', filename='css/style.css', subdomain='s0') }}" />
</head>
<body>
@@ -18,8 +18,8 @@
{% block footer %}{% endblock footer %}
- <script src="{{ url_for('static', filename='js/shadowbox.js') }}"></script>
- <script src="{{ url_for('static', filename='js/all.js') }}"></script>
+ <script src="{{ url_for('static', filename='js/shadowbox.js', subdomain='s1') }}"></script>
+ <script src="{{ url_for('static', filename='js/all.js', subdomain='s1') }}"></script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
@@ -142,8 +142,8 @@
<ul>
{% for item in screenshots.elements %}
<li>
- <a href="{{ url_for('static', filename='img/screenshots/%s/%s.png' % (screenshots.version, item.0)) }}" target="_blank">
- <img src="{{ url_for('static', filename='img/screenshots/%s/thumbnails/%s.png' % (screenshots.version, item.0)) }}" alt="" width="300" />
+ <a href="{{ url_for('static', filename='img/screenshots/{0}/{1}.png'.format(screenshots.version, item.0), subdomain='s{0}'.format((loop.index % 2) + 2)) }}" target="_blank">
+ <img src="{{ url_for('static', filename='img/screenshots/{0}/thumbnails/{1}.png'.format(screenshots.version, item.0), subdomain='s{0}'.format((loop.index % 2) + 2)) }}" alt="" width="300" />
</a>
<h3>{{ item.1 }}</h3>

0 comments on commit 6899731

Please sign in to comment.