# resource/textasset (vanilla.js 0.4.0)

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

텍스트 애셋.

## TextAsset extends Asset

텍스트 애셋.

예제: 캐시 없이 글 파일 받기

```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): 읽은 글. (읽기 전이나 언로드 뒤에는 빈 글)
  - returns string
- `constructor()` (constructor, since 0.0.8): 생성.
- `setNoCache(isNoCache)` (method, since 0.3.0): 캐시 무효화 로드 여부 설정.
  - 참이면 fetch 에 cache: "no-cache" 를 붙여, 배포 뒤 브라우저가 옛 데이터를
    계속 쓰는 문제를 막는다. (데이터 테이블 JSON 등)
  - `isNoCache` boolean: 참이면 캐시를 쓰지 않고 받는다.
- `isNoCache()` (method, since 0.3.0): 캐시 무효화 로드 여부 반환.
  - returns boolean: 캐시를 쓰지 않고 받으면 참. (기본 거짓)
- `async load(assetPath)` (method, since 0.0.8): 비동기 애셋 로드.
  - `assetPath` string: 글 파일 경로. (이미 읽혔으면 아무것도 하지 않는다)
  - returns Promise<void>: 다 읽으면 풀리는 프로미스. (실패 응답이나 받기 실패면 console.error 로 알리고 거부된다)
- `loadFromBytes(assetPath, bytes)` (method, since 0.4.0): 이미 가진 바이트로 읽기. (UTF-8 로 읽고, UTF-8 이 아닌 바이트는 대체 문자로 바꾼다, 이미 읽혔어도 새 바이트로 바꾼다)
  - `assetPath` string: getAssetPath 에 쓸 이름.
  - `bytes` ArrayBuffer | ArrayBufferView: 글 파일의 바이트. (UTF-8)
- `unload()` (method, since 0.0.8): 애셋 언로드.
