[英]javascript: Loading the same url in different iframes, how to use only one http request?
If I have different iframes
on a page and want to load the same url
in each one of them, if I simply use the same url
I can see in Developer Tools that there're as many http requests as iframes如果我在一个页面上有不同的iframes
并且想在每个 iframe 中加载相同的url
,如果我只是使用相同的url
我可以在开发人员工具中看到有尽可能多的 Z80791B3AE7002CB88F8C2468 请求
How could I prevent this to happen, and to do only one request and that this populates all iframes?我怎样才能防止这种情况发生,并且只做一个请求并且这会填充所有 iframe?
Should I load one iframe and then clone it?我应该加载一个 iframe 然后克隆它吗? This first attempt is not working第一次尝试不起作用
(React) (反应)
const [url, setUrl] = useState()
useEffect(() => {
const request = new Request('anyurl')
setUrl(request.url)
}, [])
return (
{Object.entries(iframeArray).map(() => (
<Iframe sandbox="" src={url} />
))}
)
Unfortunately, this doesn´t work, since each <iframe>
acts on its own.不幸的是,这不起作用,因为每个<iframe>
都是独立的。
Other question: Why do you want to reuse them?其他问题:为什么要重复使用它们? If you want to load static data which can be reused, please use an ajax request to load data.如果要加载可重复使用的 static 数据,请使用 ajax 请求加载数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.