mirror of https://github.com/msgbyte/tailchat
chore: 调整缓存策略, 以优化用户体验
parent
ed107d17bf
commit
dcf6d39cde
@ -1,18 +1,38 @@
|
|||||||
import { workboxPluginPattern } from '../utils';
|
import {
|
||||||
|
workboxPluginEntryPattern,
|
||||||
|
workboxPluginDetailPattern,
|
||||||
|
} from '../utils';
|
||||||
|
|
||||||
describe('workboxPluginPattern', () => {
|
describe('workboxPluginEntryPattern', () => {
|
||||||
test.each([
|
test.each([
|
||||||
// 缓存case
|
// 缓存case
|
||||||
['/plugins/com.msgbyte.foo/bar.js', true],
|
['/plugins/com.msgbyte.foo/index.js', true],
|
||||||
['/plugins/com.msgbyte.foo.foz/bar.js', true],
|
['/plugins/com.msgbyte.foo/bar/index.js', true],
|
||||||
|
|
||||||
|
// 不缓存case
|
||||||
|
['/plugins/com.msgbyte.foo/index-abcde.js', false],
|
||||||
|
['/plugins/com.msgbyte.foo/index.woff', false],
|
||||||
|
['/plugins/com.msgbyte.foo/font.woff', false],
|
||||||
|
['/plugins/a/b/c/d/e/f/g.js', false],
|
||||||
|
])('%s: %p', (input, output) => {
|
||||||
|
expect(workboxPluginEntryPattern.test(input)).toBe(output);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('workboxPluginDetailPattern', () => {
|
||||||
|
test.each([
|
||||||
|
// 缓存case
|
||||||
|
['/plugins/com.msgbyte.foo/index-abcde.js', true],
|
||||||
|
['/plugins/com.msgbyte.foo/bar-a0c1e.js', true],
|
||||||
|
['/plugins/com.msgbyte.foo.foz/bar-a0c1e.js', true],
|
||||||
|
['/plugins/com.msgbyte.foo/a/b/c/d/e/f/bar-a0c1e.js', true],
|
||||||
|
|
||||||
// 不缓存case
|
// 不缓存case
|
||||||
['/plugins/com.msgbyte.foo/index.js', false],
|
['/plugins/com.msgbyte.foo/index.js', false],
|
||||||
['/plugins/com.msgbyte.foo/index-abcde.js', false], // TODO: 这个期望是true的。但是不会写正则
|
|
||||||
['/plugins/com.msgbyte.foo/index.woff', false],
|
['/plugins/com.msgbyte.foo/index.woff', false],
|
||||||
['/plugins/com.msgbyte.foo/font.woff', false],
|
['/plugins/com.msgbyte.foo/font.woff', false],
|
||||||
['/plugins/a/b/c/d/e/f/g.js', false],
|
['/plugins/a/b/c/d/e/f/g.js', false],
|
||||||
])('%s: %p', (input, output) => {
|
])('%s: %p', (input, output) => {
|
||||||
expect(workboxPluginPattern.test(input)).toBe(output);
|
expect(workboxPluginDetailPattern.test(input)).toBe(output);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
/**
|
/**
|
||||||
* workbox 匹配plugin的缓存
|
* workbox 匹配plugin的缓存
|
||||||
*/
|
*/
|
||||||
export const workboxPluginPattern =
|
export const workboxPluginEntryPattern =
|
||||||
/plugins\/com\.msgbyte(.*?)\/((?!index).)*?\.js/;
|
/plugins\/com\.msgbyte(.*?)\/index\.js/;
|
||||||
|
|
||||||
|
export const workboxPluginDetailPattern =
|
||||||
|
/plugins\/com\.msgbyte\.(.*?)\/(\S+?)\-(\S*?)\.js/;
|
||||||
|
Loading…
Reference in New Issue