Easy URL Proxying With Proxy Prefix jQuery Plugin

File Size: 46.1 KB
Views Total: 35
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   
Easy URL Proxying With Proxy Prefix jQuery Plugin

As web developers, you might often encounter the need to manage proxied URLs, especially when dealing with static pages, content served from a Learning Management System (LMS), or various backend technologies like PHP, Java, or ASP.

Proxy Prefix is a tiny and open-source jQuery plugin that solves the hassle by automatically converting standard URLs into proxied ones directly in the browser. It handles various scenarios, including encoding special characters, stripping out invalid session IDs, and adding required authentication data for specific websites.

How it works:

The plugin first normalizes the URL and performs validation checks. It then removes irrelevant parameters and adds necessary authentication data based on website configurations. Finally, it rewrites or prefixes the URL depending on the presence of the proxy hostname within the URL itself. 

How to use it:

1. Load the jQuery library, URI.js library for URL parsing, and the Proxy Prefix plugin's script in your HTML document.

<script src="/path/to/cdn/jquery.min.js"></script>
<script src="/path/to/cdn/URI.min.js"></script>
<script src="/path/to/proxyprefix.min.js"></script>

2. Apply Proxy Prefix to the desired links and specify an array of proxy servers as follows:

<a href="https://www.jqueryscript.net">
  jQueryScript
</a>
$('a').ProxyPrefix({
  hostnames: new Array(
  'proxy.jqueryscript.net',
  'proxy1.jqueryscript.net',
  'proxy2.jqueryscript.net')
  }
);
<!-- Result -->
<a href="https://proxy.jqueryscript.net/login?qurl=https%3A%2F%2Fwww.www%2Cjqueryscript.net%2F">
  jQueryScript
</a>

3. All default plugin options.

$('a').ProxyPrefix({

  // name of element attribute to modify
  attribute: 'href',

  // URL schemes that can be proxied
  protocols: new Array( 'http', 'https' ),

  // A proxy cluster with the shared DNS name and two individual node names
  hostnames: new Array(),

  // The URL on the proxy server used as an entry point
  loginpath: '/login',

  // A list of query parameters to be stripped from URLs, by web site
  remove: {
    'web.ebscohost.com': new Array( 'sid' )
  },

  // A list of query parameters to be added to URLs, by web site
  append : {
    'search.ebscohost.com': { 
      'auth': 'uid',
      'user': 'libraryresearch',
      'password': 'libraryresearch'
    }
  }
  
});

This awesome jQuery plugin is developed by aander07. For more Advanced Usages, please check the demo page or visit the official website.