Skip to main content

Drop-In Script

Postcode Lookup shipped in a polyfilled, typed and minified package called postcode-lookup-bundled.

postcode-lookup-bundled is designed for rapid integration on a webpage or within a bundler.

Browser Integration

The fastest and simplest way to start is to drop our pre-bundled script onto a webpage.

Drop-In Script

 
<script src="https://cdn.jsdelivr.net/npm/@ideal-postcodes/postcode-lookup-bundled@2"></script>
<script>
IdealPostcodes.PostcodeLookup.setup({
apiKey: "ak_test",
context: "#context",
outputFields: {
line_1: "#line_1",
line_2: "#line_2",
line_3: "#line_3",
post_town: "#post_town",
postcode: "#postcode",
},
});
</script>

Live Demo

postcode-lookup-bundled ships a UMD compatible build, which targets IE11 and upwards.

The latest build can be downloaded here.

Demo

Loading...

ES Module

postcode-lookup-bundled also ships an ESM compatible build, targeting browsers with ESM support and upwards.

<script
type="module"
src="https://cdn.jsdelivr.net/npm/@ideal-postcodes/postcode-lookup-bundled@3/dist/postcode-lookup.esm.js"></script>

<script type="module">
import { PostcodeLookup } from "https://cdn.jsdelivr.net/npm/@ideal-postcodes/postcode-lookup-bundled@3/dist/postcode-lookup.esm.js";
PostcodeLookup.setup({
apiKey: "ak_test",
outputFields: {
line_1: "#line_1",
line_2: "#line_2",
line_3: "#line_3",
post_town: "#post_town",
postcode: "#postcode",
},
});
</script>

The latest build can be downloaded here.

Demo

Loading...

Version Control

Serving your own versioned copy is recommended. If a JavaScript CDN is used (e.g. jsDelivr, cdnjs), we strongly recommend pinning the version.

It is important you pin your bundle version in production. Pulling directly from latest will cause your integration to fail at some point in the future.

For instance, follow the instructions on jsdelivr.com/postcode-lookup-bundled to pin a major version in production.

E.g.

<script src="https://cdn.jsdelivr.net/npm/@ideal-postcodes/postcode-lookup-bundled@2"></script>

Bundler Integration

postcode-lookup-bundled can also be downloaded via npm and added to your project using bundlers like parcel, webpack or rollup. The advantage of this approach is that it may require less configuration than using the pure postcode-lookup module.

Install

npm install --save @ideal-postcodes/postcode-lookup-bundled

Use

import { PostcodeLookup } from "@ideal-postcodes/postcode-lookup-bundled";

const controller = PostcodeLookup.setup({
apiKey: "ak_test",
context: "#context",
outputFields: {
line_1: "#line_1",
line_2: "#line_2",
line_3: "#line_3",
post_town: "#post_town",
postcode: "#postcode",
},
});