- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在产品中使用谷歌地图,为了做到这一点,我需要向我的文档头添加一个脚本。该脚本包含我的应用正在使用的 google map javascript api
键。
API key
已在服务器端加载,但如果有人执行检查元素,该 key 仍会出现。为了防止这种情况(ish),我使用 jquery
从头部删除脚本。然而,这需要几秒钟的时间,并且在 API key 从 DOM 中消失之前查找它非常容易。有没有办法强制它立即被删除,这样它只在头部出现几分之一秒?
这是我正在使用的代码:
import Vue from 'vue'
let isApiSetup = false
let googleMapScript
Vue.prototype.$googleMaps = () => {
if (!isApiSetup) {
return new Promise((resolve, reject) => {
try {
isApiSetup = true
/* Resolve promise when google maps is loaded and remove script with API key from head */
window.googleMapsInit = () => {
delete window.googleMapsInit
// Remove script from head, but it takes a while
googleMapScript.remove()
resolve()
}
googleMapScript = document.createElement('SCRIPT')
googleMapScript.setAttribute(
'src',
`https://maps.googleapis.com/maps/api/js?key=${process.env.googleMapsAuthToken}&callback=googleMapsInit`
)
googleMapScript.setAttribute('async', '')
googleMapScript.setAttribute('defer', '')
document.head.appendChild(googleMapScript)
} catch (err) {
reject(err)
}
})
}
}
编辑:需要明确的是,我的 key 已经受到限制。但显然这并不能防止欺骗,因此我希望加强整体安全性。
最佳答案
使用 proxy相反。
基本上,您在服务器上设置一个端点,该端点将仅使用服务器上的 key 获取 googleMapScript,然后将获取的脚本提供给您的用户。在您的前端中,使用您的服务器端点作为 src
<script>
的。这样,API key 就永远不会提供给任何最终用户,它仅包含在从您的服务器发送到 Google API 服务器的后端请求中。
关于javascript - 使用jquery从文档头删除脚本需要几秒钟,如何使其即时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58284911/
我正在尝试将多个项目转换为 classy-prelude眼下。虽然大多数行为对我来说似乎相当简单,但 (head . head) 在简单的 2D 列表上给出了神秘的错误。 考虑以下 GHCi sess
我创建了这个类来从请求中获取 Header 值。 public class AuthenticationHeader { private static IHttpContextAccesso
这里有两段代码。 工作: joins :: [String] -> String -> String joins [] _ = "" joins [x] _ = x joins xs d = head
我是编程新手,正在Windows中使用vscode并通过Mingw 64进行编译。尝试了数天后,我要求对此问题做出解答。我用谷歌搜索了很多次。这是我的项目树的外观。请帮助我包括并将 libA 链接到
我正在研究 Ninety-Nine Scala Problems 的 P07 问题: P07 (**) Flatten a nested list structure. Example: scala>
这里有两段代码。 工作: joins :: [String] -> String -> String joins [] _ = "" joins [x] _ = x joins xs d = head
我正在使用现成的欧洲 cookie 政策脚本。问题是,我的 Hubspot CMS 只允许所有内容的全局标题或每个页面的单独标题。我们有 120 个页面,很难手动定义它,但我们需要一个用于德语页面的脚
Solaris 10 SPARC Sun Studio C 编译器 12.3 在 SPARC64 机器上,如果您访问一个在相关 4 或 8 字节边界上未正确对齐的变量,您将获得核心转储。这需要编码人员
我正在尝试从服务器列表中获取 apache 版本。我正在考虑解析 header ,但是我无法发送 HEAD 但它可以与 GET POST 等一起使用。 这是我的代码: import java.io.B
嗨,我是 github 的新手,当我对代码做了一些更改然后 merge 到上游时,如果有任何冲突,它将执行以下操作。 Auto-merging Global.asax.cs CONFLICT (con
例如,获取偏移量 Y 之后的前 X 行的建议方法是什么?我目前正在做的是: offset, limit = 2, 2 df=pd.DataFrame([{'a':1}, {'a': 2}, {'a':
当我在R块 header 中插入长标题等内容时,能够将 header 拆分为多行会很好。 有没有简单的方法可以做到这一点? 例如。: ```{r, echo=FALSE, warning=FALSE,
我刚刚开始使用 Erlang(虽然有一些 lisp 背景)并且有一个关于列表模式匹配的问题。 如果我说 [Head | Tail] = [1, 2, 3]. 然后我得到 Head = 1 Tail =
我的 index.php 文件开头有这段代码: if ( !isset($_GET['cat']) ) die(header("Location: ?cat=top")
对第 3 方应用程序进行一些 SOAP 调用。他们提供此 soap header 作为应用程序期望的示例。如何在 PHP 中创建这样的 SOAP header ?
我对 git 仓库下的文件做了一些更改,我使用 git commit 提交了文件 然后我尝试使用 git push origin master 推送到 master,它返回了 Everything u
我刚刚尝试从 url 下载 webp 图像,但是当我尝试处理存储的图像时,我发现了一些不同的东西。 如果我从浏览器下载图像,它可以使用 x/image/webp 包解码,但如果我使用 http.Get
这是来自 slices 的略微修改的代码 var buffer [256] byte func SubtractOneFromLength(slice []byte) []byte { sli
在 Linux 中是否有一种方法可以请求 Head 或 Tail 但要忽略额外的记录偏移量。 例如,如果文件 example.lst 包含以下内容: row01 row02 row03 row04 r
代码: /* * File: problem5.c * Author: levihackwith * Description: Write a Pop() function that is th
我是一名优秀的程序员,十分优秀!