# resource/textasset (vanilla.js 0.4.0)

> https://vanillapunch.com/docs/vanilla.js/0.4.0/api/resource/textasset/

Text asset.

## TextAsset extends Asset

Text asset.

Example: Fetch a text file without the cache

```js
import { TextAsset } from "./build/vanilla.js";

const textAsset = new TextAsset();
textAsset.setNoCache(true);
await textAsset.load("examples/timelineshowcase/assets/combo.timeline.json");
console.log(textAsset.text.length, textAsset.isNoCache());
```

- `text` (field, since 0.0.8): Loaded text. (empty string before loading or after unloading)
  - returns string
- `constructor()` (constructor, since 0.0.8): Constructor.
- `setNoCache(isNoCache)` (method, since 0.3.0): Sets whether to load with cache invalidation.
  - If true, adds cache: "no-cache" to fetch, preventing the browser from continuing to use old data
    after deployment. (data table JSON, etc)
  - `isNoCache` boolean: If true, fetches without using the cache.
- `isNoCache()` (method, since 0.3.0): Returns whether to load with cache invalidation.
  - returns boolean: True if fetching without the cache. (default false)
- `async load(assetPath)` (method, since 0.0.8): Loads the asset asynchronously.
  - `assetPath` string: Text file path. (does nothing if already loaded)
  - returns Promise<void>: A promise resolved when fully loaded. (on a failed response or fetch failure it reports with console.error and rejects)
- `loadFromBytes(assetPath, bytes)` (method, since 0.4.0): Loads from bytes already held. (Reads as UTF-8, replaces non UTF-8 bytes with the replacement character, replaces with the new bytes even if already loaded)
  - `assetPath` string: Name used for getAssetPath.
  - `bytes` ArrayBuffer | ArrayBufferView: Bytes of the text file. (UTF-8)
- `unload()` (method, since 0.0.8): Unloads the asset.
