Skip to main content

Transclude content via <script> tags

Project description

This simple script lets people include bits of your content (hosted on whatever server you like) into their own pages. It uses the age-old technique used by ads of issuing writes from a Javascript file.

If you mount this at http://example.com/includer.js then you can use tags like:

<script
 src="http://example.com/includer.js?url=encoded-url"></script>

<script
 src="http://example.com/includer.js?url=encoded-url%23fragment"></script>

<script
 src="http://example.com/includer.js?url=encoded-url&dest=otherId"></script>

These each include the content from the encoded-url. If you give a fragment, it grabs just the bit of identified text. If you don’t, it’ll take all the text in the <body> of the page.

It will put the output exactly where the <script> tag is in the page. If you want to put it someplace else, &dest=id will put it in the element with the given id. In that case it adds a little onload(-like) handler, and then sets the innerHTML of element with that id. If you can’t fetch the url, then it will put a small error message into the page in its place.

By default it restricts urls based on the opt-in wildcards of the allowed_urls setting. You can use allowed_urls = * to allow anything, but this is not recommended. You can also use same_host = true to allow requests to the same host as where the includer is hosted.

To minimize backend traffic, set cache_dir to a location to save the requested pages. All the caching is handled by httplib2.

Example

To run an example, install the package and use paster serve development.ini (development.ini is in the tarball). This will start up a server on http://localhost:8080/ where you can view an example.

News

0.2

  • In some cases extra <body> tags would be included in the transcluded content (when that tag should never be present).

0.1

Initial release

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

ScriptTranscluder-0.2.tar.gz (8.4 kB view hashes)

Uploaded source

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