[英]Preloading external javascripts, images and css files
I have been working on a web application which (despite my best efforts) has been steadily getting bigger and bigger with more and more scripts, images and css files being called. 我一直在开发一个Web应用程序,尽管我尽了最大努力,但随着越来越多的脚本,图像和css文件被调用,它一直在稳步增长。
Being a web application I think it is perfectly acceptable for a pre-loading screen to appear after the user has logged in and before they reach the dashboard. 作为Web应用程序,我认为在用户登录后且到达仪表板之前出现预加载屏幕是完全可以接受的。 On this page I want to call all external scripts, css files and images to be downloaded to the browser so that they are pulled from local cache rather than being downloaded on demand during the running of the application. 在此页面上,我想调用所有要下载到浏览器的外部脚本,css文件和图像,以便从本地缓存中提取它们,而不是在应用程序运行期间按需下载。
I am aware that there are billions of image preloader scripts, but I need to go one step further, with everything (mainly external scripts) being called on the page to be preloaded. 我知道有数十亿个图像预加载器脚本,但是我需要更进一步,在要预加载的页面上调用所有内容(主要是外部脚本)。
Thanks, Tim 谢谢,蒂姆
http://requirejs.org/ for script loading. http://requirejs.org/用于脚本加载。 Not sure about for css. 不确定CSS。 Also, not sure what platform you are on, but jammit for rails is pretty great for asset management. 另外,不确定您使用的平台是什么,但是对于Rails来说, 干扰对于资产管理来说是非常好的。
Although I havent seen a question in there, I am assuming we are talking about speeding up a web page loads. 尽管我在那里没有看到任何问题,但我假设我们正在谈论加快网页加载速度。
Having a preload page is a little pointless since the script ultimately has to be downloaded, so why bother sending the user to a pre load page. 有一个预加载页面是没有意义的,因为最终必须下载脚本,所以为什么要麻烦用户将其发送到预加载页面。 You simply incur additional redirect requests. 您只需招致其他重定向请求。
You got 3 main ways to reduce load times: 您有3种减少加载时间的主要方法:
Combres (.NET) is great and handles concatination and minification of scripts and CSS. Combres(.NET)很棒,可以处理脚本和CSS的缩写和缩小。 I am sure there is something similar for other tech stacks. 我确信其他技术堆栈也有类似的东西。 This limits the number of files downloaded (also providing a minification hook) 这限制了下载文件的数量(还提供了一个缩小挂钩)
Also make sure you are using CSS sprites. 还要确保您使用的是CSS Sprite。 This limits the number of images downloaded 这限制了下载的图像数量
As far as size goes: 就大小而言:
You havent mentioned the tech stack you are on, but try look at some script minification libraries (YUI Compressor, etc). 您还没有提到您所使用的技术堆栈,但是请尝试查看一些脚本缩小库(YUI Compressor等)。
Also make sure you are using GZip (via either IIS config or on hardware via load balancer or whatever) 另外,请确保您使用的是GZip(通过IIS配置或通过负载平衡器或任何其他方式在硬件上)
There is also several javascript techniques that you can use to perform JIT downloads of scripts and basically prioritize the user exeprience. 您还可以使用多种JavaScript技术来执行JIT脚本下载,并从根本上确定用户的优先级。 Steve Souders has some great books on these techniques 史蒂夫·索德斯(Steve Souders)有一些关于这些技术的好书
After these approaches you then start to look for hardware solutions like CDN's, etc. These ensure your content sits close to your target audience for faster downloads. 使用这些方法之后,您便开始寻找CDN等硬件解决方案。这些确保您的内容位于目标受众附近,以加快下载速度。
Yahoo have some great guidance on this: http://developer.yahoo.com/performance/rules.html 雅虎对此有一些很好的指导: http : //developer.yahoo.com/performance/rules.html
You can : 您可以 :
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.