Skip to main content

Machinery to include web resources based on request layer.

Project description

Overview

The package is able to include the following types of resources:

  • Cascading stylesheets (.css)

  • Kinetic stylesheets (.kss)

  • Javascript (.js)

Usage

The package operates with browser resources, registered individually or using the resource directory factory.

A simple example:

<configure xmlns="http://namespaces.zope.org/zope"
          xmlns:browser="http://namespaces.zope.org/browser">

  <include package="z3c.resourceinclude" file="meta.zcml" />
  <include package="z3c.resourceinclude" />

  <browser:resource name="example.css" file="example.css" />

  <browser:resourceInclude
       layer="zope.publisher.interfaces.browser.IDefaultBrowserLayer"
       include="example.css"
   />

</configure>

This registration means that whenever the request provides IDefaultBrowserLayer the resource named ‘example.css’ will be included on the page.

To render HTML snippets that include applicable resources, a content provider is provided, see z3c/resourceinclude/provide.py. You may also use one of the viewlets:

<browser:viewlet
   name="resourceinclude"
   class="z3c.resourceinclude.viewlets.CacheOneHourViewlet"
   permission="zope.View" />

A convenience method is provided to require a given resource layer:

>>> from z3c.resourceinclude import include
>>> include(IMyLayer)

Ordering

Resources are included in the order they’re registered; that is, the order in which the ZCML-directives are processed.

Stylesheets are included before javascripts as per general recommendation. Kinetic stylesheets are included last.

Merging

When not in ‘devmode’, the resource collector will automatically merge resources, giving them a filename based on the contents (sha digest). This has the side effect that merged resources are set to never expire.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

z3c.resourceinclude-0.3.1.tar.gz (9.9 kB view details)

Uploaded Source

File details

Details for the file z3c.resourceinclude-0.3.1.tar.gz.

File metadata

File hashes

Hashes for z3c.resourceinclude-0.3.1.tar.gz
Algorithm Hash digest
SHA256 92fe4b47e02d06aae7fb8fae55bf2da5c3da35d95993f89394b61885cdd37d21
MD5 b1773a238ca919da0300df305090b5be
BLAKE2b-256 9ce162f797235fc80b0ab78ed23fac25cf64fb007a28aee601b94fe9edca50f5

See more details on using hashes here.

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