offline
Learn more about using this API here
The sos.offline
API groups together methods for storing and using JS, CSS and font files.
Emulator has certain limitations while handling offline files. Read more here
Methods
addFile()
The addFile()
method downloads the specified file and stores it locally.
addFile(file: ISaveFile): Promise<void>;
Example
await sos.offline.addFile({
// Source URL
uri: 'https://code.jquery.com/jquery-3.7.1.slim.min.js',
// Unique identifier of the resource
uid: 'jquery-3.7.1.slim.min.js',
// Indicate that the downloaded file is a JavaScript file
type: sos.offline.types.javascript,
// After the file is downloaded, it will be appended to document.body
flags: [sos.offline.flags.append(document.body)],
});
addFiles()
The addFiles()
method downloads the specified files and stores them locally. The order in which the files are downloaded and stored is not guaranteed.
addFiles(files: ISaveFile[]): Promise<void[]>;
Example
await sos.offline.addFile([{
uri: 'https://unpkg.com/normalize.css@8.0.1/normalize.css',
uid: 'normalize.css',
type: sos.offline.types.css,
flags: [sos.offline.flags.append(document.head)],
}, {
uri: 'https://code.jquery.com/jquery-3.7.1.slim.min.js',
uid: 'jquery-3.7.1.slim.min.js',
type: sos.offline.types.javascript,
flags: [sos.offline.flags.append(document.body)],
}]);
addFilesSync()
The addFilesSync()
method downloads the specified files and stores them locally. The order in which the files are downloaded and stored is guaranteed.
addFilesSync(files: ISaveFile[]): Promise<void>;
addFont()
The addFont()
method downloads the specified file and stores it locally. You should use this method for loading fonts instead of
using addFile()
, because it also generates appropriate font-face definition.
addFont(font: IAddFont): Promise<void>;
Params
Name | Type | Description |
---|---|---|
font.uid | string | Unique file identifier is used for later file retrieval, must contain a-z,A-Z,0-9 and . characters. |
font.append | HTMLElement | Reference to HTMLElement where the generated font-face will resist. |
font.fontFamily | string | Font family that can be referenced from your CSS. |
font.formats | IFontFormats | URI where these formats will be downloaded from. |
font.fontStretch (optional) | string | Allows you to make text wider or narrower. |
font.fontStyle (optional) | IFontStyle | Specifies the font style for a text. (Either normal , italic , oblique , initial or inherit ) |
font.fontWeight (optional) | string | Sets how thick or thin characters in text should be displayed |
font.unicodeRange (optional) | string | Defines the range of unicode characters the font supports, default value is "U+0-10FFFF" |
font.formats | IFontFormats | Dictionary of supported formats with its files |