考虑一下这view会生成ico图像:
from django.http import HttpResponse
from app.somewhere import Favicon
# View URL: `/<str:colour>.ico`
def favicon( request, colour ):
response = HttpResponse(
Favicon.render( colour ),
status=200
)
response['Content-Type'] = 'image/x-icon'
response['Cache-Control'] = 'public, max-age=31536000'
return response
Run Code Online (Sandbox Code Playgroud)
Favicon.render() 返回一个有效的字节流,对此不用理会。
这是我的HTML文档中的link元素head:
<link rel=icon href=/7f9fa4.ico>
Run Code Online (Sandbox Code Playgroud)
现在出现了一个问题:为什么每次我重新加载页面时,浏览器Chromium 73都会向发送请求/7f9fa4.ico,而不是从缓存中检索图标?如果我将/7f9fa4.ico在新标签页中打开,则将首次向服务器发送请求,然后我的浏览器将从缓存中检索图像;现在告诉我浏览器缓存系统出了什么问题。
这是一个请求(忽略cookie和首选项):
GET /7f9fa4.ico HTTP/1.1
Host: localhost:8000
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) …Run Code Online (Sandbox Code Playgroud) 当启用平滑滚动时,如何使用 JavaScript 立即将窗口滚动到某个位置?
:root {
scroll-behavior: smooth;
}
Run Code Online (Sandbox Code Playgroud)
有没有办法忽略这个 CSS 规则?像这样的东西:
window.scrollBy({ top: 0, behavior: 'instantly' });
Run Code Online (Sandbox Code Playgroud) 考虑这个template带有两个 flatx-element和一个嵌套的HTML 。
<template id="fooTemplate">
<x-element>Enter your text node here.</x-element>
<x-element>
<x-element>Hello, World?</x-element>
</x-element>
</template>
Run Code Online (Sandbox Code Playgroud)
如何初始化(触发构造函数)从fooTemplate文档片段克隆的所有自定义元素而不将其附加到 DOM,也不是通过使用is="x-element";扩展内置元素;要么是整个片段。
class XElement extends HTMLElement {
constructor() { super(); }
foo() { console.log( this ); }
} customElements.define( 'x-element', XElement );
const uselessf = function( temp ) {
const frag = window[ temp ].content.cloneNode( true );
/* Your magic code goes here:
*/ do_black_magic( frag );
for (const e of frag.querySelectorAll('x-element') )
e.foo(); // This should …Run Code Online (Sandbox Code Playgroud) html javascript documentfragment custom-element html-templates
如何像javascript一样将数组破坏为参数列表?
def foo( arg0, arg1 ): pass
bar = [ 32, 44 ]
foo( ...bar )
Run Code Online (Sandbox Code Playgroud) 是否可以counter根据其值填充数字?
div {
counter-reset: ruler;
}
div > span {
display: block;
line-height: 1rem;
}
div > span::before {
counter-increment: ruler;
content: counter( ruler ) ' ';
}Run Code Online (Sandbox Code Playgroud)
<div>
<span>Hello, World!</span>
<span>Hello, World!</span>
<span>Hello, World!</span>
<span>Hello, World!</span>
<span>Hello, World!</span>
<span>Hello, World!</span>
<span>Hello, World!</span>
<span>Hello, World!</span>
<span>Hello, World!</span>
<span>Hello, World!</span>
<span>Hello, World!</span>
<span>Hello, World!</span>
<span>Hello, World!</span>
</div>Run Code Online (Sandbox Code Playgroud)
就像如果有 42 行,数字将像09或 9、 420 —009或 9。
考虑以下基本自定义元素:
class XElement extends HTMLElement {
constructor() { super(); }
foo() { console.log( this ); }
} customElements.define( 'x-element', XElement );
Run Code Online (Sandbox Code Playgroud)
这是问题所在:
const xelem = new XElement();
/* `foo` will lose its binding to `xelem`:
*/ someButton.onclick = xelem.foo;
// These will work, but it's too verbose:
someButton.onclick = () => xelem.foo();
someButton.onclick = xelem.foo.bind( xelem );
Run Code Online (Sandbox Code Playgroud)
我看到只有一种解决方案是foo在构造函数中添加为箭头函数,但是在我看来这是错误的。
constructor() {
super();
this.foo = () => console.log( this );
}
Run Code Online (Sandbox Code Playgroud)
有没有正确的方法来创建永远不会失去其绑定的方法?
假设我想将passwd内容存储在一个变量中,就像这样:
local passwd = io.open('/etc/passwd', 'r'):read('a')
Run Code Online (Sandbox Code Playgroud)
我读完后没有关闭文件可以吗?我应该像这样重写它:
local f = io.open('/etc/passwd', 'r')
local passwd = f:read('a')
f:close()
Run Code Online (Sandbox Code Playgroud)
我知道第一段代码有效,但我没有——如果它会导致一些隐藏的问题。
我正在使用 Lua 5.3
javascript ×4
html ×2
arguments ×1
arrays ×1
caching ×1
css ×1
css-counter ×1
django ×1
fclose ×1
file ×1
fopen ×1
function ×1
http ×1
http-caching ×1
io ×1
lua ×1
python ×1
scroll ×1
this ×1
zero-padding ×1