Skip to main content

An extension to manage and serve your javascript assets with bower

Project description

Flask-Bower provides a method to manage and serve bower installed packages. This simplifies javascript dependency management a lot.

To provide this, there is a flask blueprint to serve content from your bower_components directory and a custom bower_url_for() function to generate the appropriate urls


First you have to add it to your app:

from flask_bower import Bower



This provides the /bower url route and a new jinja2 function bower_url_for()

The bower_components directory has do be inside the app directory (app/bower_components - like your static and templates directories)

Install your packages like jquery with bower: bower install -S jquery

Now it should look like:

$ ls -1 app/bower_components/jquery

To include and use this, you can use bower_url_for():

<script src="{{ bower_url_for('jquery', 'dist/jquery.js') }}"></script>

Which will produce an url like (example is with BOWER_SUBDOMAIN=static):

<script src=""></script>

The Syntax is: bower_url_for(component, filename, parameters)

component is the package name (like jquery).
filename is the actual file inside the package like dist/jquery.js (also see BOWER_TRY_MINIFIED below)
parameters can be any key=value combination, which will be added to the produced url as parameter


There are several configuration options to customize the behavior:


default: bower_components

Directory name containing your installed bower packages


default: True

Append ?version= parameter to url (useful for cache busting by updates). It tries to detect the version in the following order:

  1. bower.json

  2. package.json (if available)

  3. file modification timestamp


default: True

Check if a minified version is available and serve this instead (check if a file with <filename>.min.<ext> like dist/jquery.min.js exists)


default: /bower

Customize the url prefix


default: None

Subdomain to serve the content like static (see flask blueprint documentation for subdomains)

Project details

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page