如何让我的主页速度非常快?
它有效,我想让它变得超级快。 索引页非常静态,除非日期更新或地图更新,否则几天内不会真正发生变化。所以应该可以优化得非常快,因为它没有太大变化。我最近迁移到 HRD,我的 URI 是 montaoproject.appspot.com 我重写了这个,以便它只有 python 和 django / html (没有数据层行程。) Memcache?其他选择?减少JavaScript?我首先确保数据层没有被触及:
def get(self):
logo = ''
if get_host().find('.br') > 0:
cookie_django_language = 'pt-br'
logo = 'montao'
elif get_host().find('allt') > 0 and not self.request.get('hl'):
logo = ''
cookie_django_language = 'sv'
elif get_host().find('gralumo') > 0 \
and not self.request.get('hl'):
cookie_django_language = 'es_AR' # learn
else:
logo = ''
cookie_django_language = self.request.get('hl', '') # edit
if cookie_django_language:
if cookie_django_language == 'unset':
del self.request.COOKIES['django_language']
else:
self.request.COOKIES['django_language'] = \
cookie_django_language
translation.activate(cookie_django_language)
loginmsg = ''
user = users.get_current_user()
twittername = None
client = OAuthClient('twitter', self)
if client.get_cookie():
info = client.get('/account/verify_credentials')
twittername = info['screen_name']
# seconds_valid = 8600
# self.response.headers['Cache-Control'] = "public, max-age=%d" % seconds_valid
if logo == 'montao':
self.render(
u'montao',
host=get_host(),
twittername=twittername,
continue_url=get_host(),
loginmsg=loginmsg,
form_url=blobstore.create_upload_url('/fileupload'),
user_url=(api.users.create_logout_url(self.request.uri) if api.users.get_current_user() else api.users.create_login_url(self.request.uri)),
admin=users.is_current_user_admin(),
user=(users.get_current_user() if users.get_current_user() else ''
),
logo=logo,
)
else:
self.render(
u'home',
host=get_host(),
twittername=twittername,
continue_url=get_host(),
loginmsg=loginmsg,
form_url=blobstore.create_upload_url('/fileupload'),
latest=Ad.all().filter('published =',
True).order('-modified').get(),
user_url=(api.users.create_logout_url(self.request.uri) if api.users.get_current_user() else api.users.create_login_url(self.request.uri)),
admin=users.is_current_user_admin(),
guser=(users.get_current_user() if users.get_current_user() else ''
),
logo=logo,
)
It works and I want to make it super fast. The index page is very static, doesn't really change for days unless date updates or a map updates. So it should be possible to optimize to very fast since it doesn't change much. I recently migrated to HRD and my URI is montaoproject.appspot.com I rewrote this so that it is only python and django / html (no data layer trip.) Memcache? Other options? Reduce javascript? I first made sure that data layer isn't touched:
def get(self):
logo = ''
if get_host().find('.br') > 0:
cookie_django_language = 'pt-br'
logo = 'montao'
elif get_host().find('allt') > 0 and not self.request.get('hl'):
logo = ''
cookie_django_language = 'sv'
elif get_host().find('gralumo') > 0 \
and not self.request.get('hl'):
cookie_django_language = 'es_AR' # learn
else:
logo = ''
cookie_django_language = self.request.get('hl', '') # edit
if cookie_django_language:
if cookie_django_language == 'unset':
del self.request.COOKIES['django_language']
else:
self.request.COOKIES['django_language'] = \
cookie_django_language
translation.activate(cookie_django_language)
loginmsg = ''
user = users.get_current_user()
twittername = None
client = OAuthClient('twitter', self)
if client.get_cookie():
info = client.get('/account/verify_credentials')
twittername = info['screen_name']
# seconds_valid = 8600
# self.response.headers['Cache-Control'] = "public, max-age=%d" % seconds_valid
if logo == 'montao':
self.render(
u'montao',
host=get_host(),
twittername=twittername,
continue_url=get_host(),
loginmsg=loginmsg,
form_url=blobstore.create_upload_url('/fileupload'),
user_url=(api.users.create_logout_url(self.request.uri) if api.users.get_current_user() else api.users.create_login_url(self.request.uri)),
admin=users.is_current_user_admin(),
user=(users.get_current_user() if users.get_current_user() else ''
),
logo=logo,
)
else:
self.render(
u'home',
host=get_host(),
twittername=twittername,
continue_url=get_host(),
loginmsg=loginmsg,
form_url=blobstore.create_upload_url('/fileupload'),
latest=Ad.all().filter('published =',
True).order('-modified').get(),
user_url=(api.users.create_logout_url(self.request.uri) if api.users.get_current_user() else api.users.create_login_url(self.request.uri)),
admin=users.is_current_user_admin(),
guser=(users.get_current_user() if users.get_current_user() else ''
),
logo=logo,
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不懂Python,但如果它几天都没有改变,我相信你可以写一些东西将上面的内容转换为HTML(比如每小时),然后只提供HTML版本。这将为您提供尽可能最大的优化之一,因为您的主页根本不需要由脚本引擎处理。
I don't know python, but if it doesn't change for days I am sure you could write something to convert the above into HTML (say every hour), and then just serve the HTML version. That will give you one of the largest optimisations possible, since your home page then doesn't have to be processed by a script engine at all.
通常,我建议反转页面,将 index.html 作为静态文件以及 css 和 js 文件放入,然后向服务器发出 AJAX 请求以填充动态位。静态文件加载速度非常快。
您仍然可以通过使用客户端 JavaScript 来确定要使用哪个徽标等来实现这一点,但是呈现文件上传表单会更慢,因为
create_upload_url
需要发生在服务器端。Normally, I'd recommend inverting the page, putting index.html out as a static-file, as well as css and js files, then making an AJAX request to the server to fill in dynamic bits. Static files load really fast.
You might still be able to pull that off, by using client-side JavaScript to figure out which logo and such to use, but getting the file upload form rendered is going to be slower, since the
create_upload_url
needs to happen server side.