Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
65 lines (48 sloc) 2.81 KB

Android Components > Libraries > Public Suffix List

A library for reading and using the Public Suffix List.

A "public suffix" is one under which Internet users can (or historically could) directly register names. Some examples of public suffixes are .com, and The Public Suffix List is a list of all known public suffixes.


Setting up the dependency

Use Gradle to download the library from (Setup repository):

implementation "org.mozilla.components:lib-publicsuffixlist:{latest-version}"

Using the public suffix list

The PublicSuffixList class offers multiple methods for using the public suffix list data. For every instance the list needs to be read from disk into memory once. Therefore all methods return Deferred types. The list data is cached in the PublicSuffixList and therefore it is recommended to keep a single instance in memory when frequently accessing the list. The list data can be prefetched to guarantee fast access for subsequent access.

val publicSuffixList = PublicSuffixList(context)

// Not needed, but allows a consumer to decide when the read is happening:
 // Optionally you can wait for the read to complete:
// Extracting the effective top-level domain (eTLD)
publicSuffixList.getPublicSuffixPlusOne("") // ->
publicSuffixList.getPublicSuffixPlusOne("") // ->
publicSuffixList.getPublicSuffixPlusOne("") // ->
// Checking whether a value is a public suffix:
publicSuffixList.isPublicSuffix("org") // -> true
publicSuffixList.isPublicSuffix("") // -> true
publicSuffixList.isPublicSuffix("org") // -> true
publicSuffixList.isPublicSuffix("") --> true
// Extracting the public suffix from a domain
publicSuffixList.getPublicSuffix("") // -> org
publicSuffixList.getPublicSuffix("") // ->
publicSuffixList.getPublicSuffix("") // ->
// Removing the public suffix from a domain
publicSuffixList.stripPublicSuffix("") // -> www.mozilla
publicSuffixList.stripPublicSuffix("") // -> foobar
publicSuffixList.stripPublicSuffix("") // -> www.example


This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at
You can’t perform that action at this time.