npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jquery-bifrost

v1.0.2

Published

A jQuery Ajax transport that uses an iframe to asynchronously send files and data even if FormData, the File API and XMLHttpRequest aren't supported.

Downloads

2

Readme

jQuery Bifröst

NPM

A jQuery Ajax transport that uses the hidden iframe technique to make asynchronous requests, allowing to send both files and data even from browsers that don't support FormData, the File API or XMLHttpRequest at all.

(1.3kb minified and gzipped)

Setup

  1. Load the required files, jquery.js and jquery.bifrost.js.

  2. Make a regular $.ajax() request setting the proper dataType:

    $.ajax({
      url: 'path/to/asgard',
      method: 'POST',
      dataType: 'iframe json',
      data: { title: 'Lorem ipsum', description: 'Some data...' },
      fileInputs: $('input[type="file"]')
    }).done(function(data){
      console.log(data);
    }).fail(function(){
      console.log('Request failed!');
    });

    Special options:

    • dataType: sets the transport to use (iframe) and the type of data to expect (json in this case), separated by only one space.

    • fileInputs (optional): allows to send/upload files, it takes the file inputs containing the files to be sent.

  3. Enjoy! That's it, you are now using a hidden iframe instead of XMLHttpRequest.

Headers

When using an iframe is not possible to set custom headers, so additional headers are appended as metadata to the data object and are sent as part of the request body or the URL query as appropriate.

By default the plugin adds the following metadata to help identify and process the request:

  • X-Requested-With: set to "IFrame".
  • Accept: depends on the dataType and accepts options (see jQuery.ajax).
  • _method: if the method option (or type for jQuery prior to 1.9.0) is other than GET or POST (DELETE, PUT, PATCH, etc.) the request's method is changed to POST and _method holds the original method.

Custom headers set in the headers option will also be appended as metadata and overwrite the built-in ones.

If for any reason you need to keep the data object clean (no additional data), just set the headers option to false. No headers/metadata will be appended.

Testing

There is a built-in set of QUnit tests that you can run on any browser you want to make sure it's properly supported.

The tests depend on Jaqen, a minimal testing server that allows to easily emulate APIs by setting the desired responses on the very requests.

See the testing doc page for more information.

Acknowledgments

This transport is heavily inspired by this two projects: jQuery Iframe Transport and the Iframe Transport from jQuery File Upload.

The reasons for yet another implementation are that the first one needs a textarea within the response to work properly, the second one isn't a separately maintained project, and both have good features that are missing in the other.

This implementation aims to get the best out of both and to add some improvements where possible.

Why the name?

The name is an analogy to the Norse mythology where the Bifröst is a magic bridge between Midgard (abode of mankind) and Asgard (the realm of the gods).

In this context the iframe is an almost magic fallback bridge between browser and server to send files and data asynchronously when otherwise unsupported.

Contributing

Anyone is welcomed and encouraged to open up issues and report bugs. You may make pull requests (in a feature branch) if you want but keep in mind that the main goal here is to keep it simple.