Project

General

Profile

addMetaHeader ?

Added by yu feng over 6 years ago

hi:

In my MyWebApp add addMetaHeader function:

MyWebApp::MyWebApp(const Wt::WEnvironment& env)

: Wt::WApplication(env)

{

...

addMetaHeader(Wt::MetaHeaderType::HttpHeader,"viewport","width=device-width, initial-scale=1");

...

}

In html head only

,can not add this line

why?


Replies (5)

RE: addMetaHeader ? - Added by Frode Roxrud Gill over 6 years ago

Somewhere (can't remember where) this exact problem is explained. The header has to be present too early for the application lifetime, so you have to set it in the config file.

Find the file you are using (or use the global wt_config.xml if that is ok for you) and add this near the meta-header robots line:

RE: addMetaHeader ? - Added by Kayra Akman over 6 years ago

I use this line of code as the first line in the constructor:

addMetaHeader(Wt::MetaName, "viewport", "width=device-width, initial-scale=1");

Note the first argumet to addMetaHeader(). MetaName is correct enum value to use.

It works as expected. There is no need to change the config file for this.

PS: I use Wt3. In Wt4 the enum value should be changed to include enum name as well, as you did in your example.

RE: addMetaHeader ? - Added by Frode Roxrud Gill about 6 years ago

Are you sure about this? If I add the MetaHeader in C code I get this in my application log when a client connects:

"[2018-Feb-21 15:42:02.172] 12434 [/ pVqEuznyA6xgJNOG] [warning] "WApplication: WApplication::addMetaHeader() with no effect\" \"

Adding the MetaHeader in wt_config.xml gives no such warning, and activates responsive design.

RE: addMetaHeader ? - Added by Kayra Akman about 6 years ago

Yes, I am sure. Several apps are working this way for years.

RE: addMetaHeader ? - Added by Wim Dumon about 6 years ago

It depends on the bootstrapping method. With progressive bootstrap it's ok to use addMetaHeader() in the constructor, with the default bootstrapping method, the first page is already rendered at that time and the modifiations of the (some?) meta header don't have the proper effect anymore. Progressive bootstrap is configured in wt_config.xml.

BR,

Wim.

    (1-5/5)